From: Uwe Hermann Date: Wed, 2 Aug 2017 06:14:31 +0000 (+0200) Subject: rowdata: Use emplace_back() for Annotation objects. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=1becee23bdd2b44145b753edd05bf01f7fb0707e;p=pulseview.git rowdata: Use emplace_back() for Annotation objects. This should eliminate one unnecessary allocation per annotation. --- diff --git a/pv/data/decode/rowdata.cpp b/pv/data/decode/rowdata.cpp index 02859b27..aff4a26b 100644 --- a/pv/data/decode/rowdata.cpp +++ b/pv/data/decode/rowdata.cpp @@ -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 diff --git a/pv/data/decode/rowdata.hpp b/pv/data/decode/rowdata.hpp index 3cb69b3e..07cc41bf 100644 --- a/pv/data/decode/rowdata.hpp +++ b/pv/data/decode/rowdata.hpp @@ -22,6 +22,8 @@ #include +#include + #include "annotation.hpp" using std::vector; @@ -45,7 +47,7 @@ public: vector &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 annotations_; diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index 7e01dd8a..b39904a2 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -940,18 +940,21 @@ void DecodeSignal::annotation_callback(srd_proto_data *pdata, void *decode_signa lock_guard 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)