]> sigrok.org Git - pulseview.git/commitdiff
rowdata: Use emplace_back() for Annotation objects.
authorUwe Hermann <redacted>
Wed, 2 Aug 2017 06:14:31 +0000 (08:14 +0200)
committerUwe Hermann <redacted>
Fri, 22 Sep 2017 10:03:14 +0000 (12:03 +0200)
This should eliminate one unnecessary allocation per annotation.

pv/data/decode/rowdata.cpp
pv/data/decode/rowdata.hpp
pv/data/decodesignal.cpp

index 02859b2790a5b10f7979653ccc1ff41f8000e84c..aff4a26b333b68b2672af073c87b8ad5c392d406 100644 (file)
@@ -42,9 +42,9 @@ void RowData::get_annotation_subset(
                        dest.push_back(annotation);
 }
 
-void RowData::push_annotation(const Annotation &a)
+void RowData::emplace_annotation(srd_proto_data *pdata)
 {
-       annotations_.push_back(a);
+       annotations_.emplace_back(pdata);
 }
 
 }  // namespace decode
index 3cb69b3ef1b5ad84ad95581c961c9a4f9694850f..07cc41bf3eb1f8febf04c06595d8da2f142eb7da 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <vector>
 
+#include <libsigrokdecode/libsigrokdecode.h>
+
 #include "annotation.hpp"
 
 using std::vector;
@@ -45,7 +47,7 @@ public:
                vector<pv::data::decode::Annotation> &dest,
                uint64_t start_sample, uint64_t end_sample) const;
 
-       void push_annotation(const Annotation &a);
+       void emplace_annotation(srd_proto_data *pdata);
 
 private:
        vector<Annotation> annotations_;
index 7e01dd8a3f1742c1dd5924709239efd3031d35f3..b39904a2200090fb6d624f7cc7d9f9b216a7dacf 100644 (file)
@@ -940,18 +940,21 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa
 
        lock_guard<mutex> lock(ds->output_mutex_);
 
-       const decode::Annotation a(pdata);
-
        // Find the row
        assert(pdata->pdo);
        assert(pdata->pdo->di);
        const srd_decoder *const decc = pdata->pdo->di->decoder;
        assert(decc);
 
+       const srd_proto_data_annotation *const pda =
+               (const srd_proto_data_annotation*)pdata->data;
+       assert(pda);
+
        auto row_iter = ds->rows_.end();
 
        // Try looking up the sub-row of this class
-       const auto r = ds->class_rows_.find(make_pair(decc, a.format()));
+       const auto format = pda->ann_class;
+       const auto r = ds->class_rows_.find(make_pair(decc, format));
        if (r != ds->class_rows_.end())
                row_iter = ds->rows_.find((*r).second);
        else {
@@ -962,13 +965,13 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa
        assert(row_iter != ds->rows_.end());
        if (row_iter == ds->rows_.end()) {
                qDebug() << "Unexpected annotation: decoder = " << decc <<
-                       ", format = " << a.format();
+                       ", format = " << format;
                assert(false);
                return;
        }
 
        // Add the annotation
-       (*row_iter).second.push_annotation(a);
+       (*row_iter).second.emplace_annotation(pdata);
 }
 
 void DecodeSignal::on_capture_state_changed(int state)