This patch was generated using clang-tidy:
clang-tidy -checks="-*,modernize-use-emplace" -fix
Using emplace_back() has multiple advantages:
- It's usually shorter and easier to read.
- It's more efficient.
V1: v.push_back("foo");
V2: v.emplace_back("foo");
V1 will construct a temporary std::string from the string literal "foo",
another copy of that temporary object will be constructed and placed
into the vector 'v', then the temporary object's destructor will be called.
V2 will simply create a std::string directly in the vector 'v', i.e.
there's only one construction (not 2) and no destructor needs to be called.
// Add a row for the decoder if it doesn't have a row list
if (!decc->annotation_rows)
// Add a row for the decoder if it doesn't have a row list
if (!decc->annotation_rows)
- rows.push_back(Row(decc));
+ rows.emplace_back(decc);
// Add the decoder rows
for (const GSList *l = decc->annotation_rows; l; l = l->next) {
const srd_decoder_annotation_row *const ann_row =
(srd_decoder_annotation_row *)l->data;
assert(ann_row);
// Add the decoder rows
for (const GSList *l = decc->annotation_rows; l; l = l->next) {
const srd_decoder_annotation_row *const ann_row =
(srd_decoder_annotation_row *)l->data;
assert(ann_row);
- rows.push_back(Row(decc, ann_row));
+ rows.emplace_back(decc, ann_row);
// Store the initial state
last_sample = (get_unpacked_sample(start) & sig_mask) != 0;
// Store the initial state
last_sample = (get_unpacked_sample(start) & sig_mask) != 0;
- edges.push_back(pair<int64_t, bool>(index++, last_sample));
+ edges.emplace_back(index++, last_sample);
while (index + block_length <= end) {
//----- Continue to search -----//
while (index + block_length <= end) {
//----- Continue to search -----//
// Store the final state
const bool final_sample =
(get_unpacked_sample(final_index - 1) & sig_mask) != 0;
// Store the final state
const bool final_sample =
(get_unpacked_sample(final_index - 1) & sig_mask) != 0;
- edges.push_back(pair<int64_t, bool>(index, final_sample));
+ edges.emplace_back(index, final_sample);
index = final_index;
last_sample = final_sample;
index = final_index;
last_sample = final_sample;
// Add the final state
const bool end_sample = get_unpacked_sample(end) & sig_mask;
if (last_sample != end_sample)
// Add the final state
const bool end_sample = get_unpacked_sample(end) & sig_mask;
if (last_sample != end_sample)
- edges.push_back(pair<int64_t, bool>(end, end_sample));
- edges.push_back(pair<int64_t, bool>(end + 1, end_sample));
+ edges.emplace_back(end, end_sample);
+ edges.emplace_back(end + 1, end_sample);
}
uint64_t LogicSegment::get_subsample(int level, uint64_t offset) const
}
uint64_t LogicSegment::get_subsample(int level, uint64_t offset) const
settings.setValue("device_type", "hardware");
settings.beginGroup("device");
settings.setValue("device_type", "hardware");
settings.beginGroup("device");
- key_list.push_back("vendor");
- key_list.push_back("model");
- key_list.push_back("version");
- key_list.push_back("serial_num");
- key_list.push_back("connection_id");
+ key_list.emplace_back("vendor");
+ key_list.emplace_back("model");
+ key_list.emplace_back("version");
+ key_list.emplace_back("serial_num");
+ key_list.emplace_back("connection_id");
dev_info = device_manager_.get_device_info(device_);
dev_info = device_manager_.get_device_info(device_);
// Re-select last used device if possible but only if it's not demo
settings.beginGroup("device");
// Re-select last used device if possible but only if it's not demo
settings.beginGroup("device");
- key_list.push_back("vendor");
- key_list.push_back("model");
- key_list.push_back("version");
- key_list.push_back("serial_num");
- key_list.push_back("connection_id");
+ key_list.emplace_back("vendor");
+ key_list.emplace_back("model");
+ key_list.emplace_back("version");
+ key_list.emplace_back("serial_num");
+ key_list.emplace_back("connection_id");
for (string key : key_list) {
const QString k = QString::fromStdString(key);
for (string key : key_list) {
const QString k = QString::fromStdString(key);