]> sigrok.org Git - pulseview.git/commitdiff
Use emplace_back() where possible.
authorUwe Hermann <redacted>
Fri, 10 Mar 2017 20:32:43 +0000 (21:32 +0100)
committerUwe Hermann <redacted>
Sat, 11 Mar 2017 12:06:03 +0000 (13:06 +0100)
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.

pv/data/decoderstack.cpp
pv/data/logicsegment.cpp
pv/session.cpp

index 11b2b70bebc65e7503abc2dca66bf78bac54342a..1f158c230b7f55c53630c0eb2e78f5f09ded6ed4 100644 (file)
@@ -145,14 +145,14 @@ std::vector<Row> DecoderStack::get_visible_rows() const
 
                // 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);
-                       rows.push_back(Row(decc, ann_row));
+                       rows.emplace_back(decc, ann_row);
                }
        }
 
index bdfc98167b81df85132c2ce2c5310bbe4b62fc52..5191a3f03e76a2654202f84039e18d574898b56e 100644 (file)
@@ -322,7 +322,7 @@ void LogicSegment::get_subsampled_edges(
 
        // 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 -----//
@@ -458,7 +458,7 @@ void LogicSegment::get_subsampled_edges(
                // 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;
@@ -467,8 +467,8 @@ void LogicSegment::get_subsampled_edges(
        // 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
index ef2f39bb8ed3ddb88ded541959042ad531a5096a..e5bf1f6a3dee58a7f15e42005e7cbcaef0ace961 100644 (file)
@@ -193,11 +193,11 @@ void Session::save_settings(QSettings &settings) const
                        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_);
 
@@ -277,11 +277,11 @@ void Session::restore_settings(QSettings &settings)
 
                // 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);