From: Joel Holdsworth Date: Sat, 28 Mar 2015 12:10:14 +0000 (+0000) Subject: Session: Store signals_ in an unordered_set X-Git-Tag: pulseview-0.3.0~229 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=78b0af3ebcbeab50e1c1634af729c0a7f97fb435;p=pulseview.git Session: Store signals_ in an unordered_set --- diff --git a/pv/popups/channels.cpp b/pv/popups/channels.cpp index 61a8aee0..3d209e84 100644 --- a/pv/popups/channels.cpp +++ b/pv/popups/channels.cpp @@ -42,6 +42,7 @@ using std::map; using std::mutex; using std::set; using std::shared_ptr; +using std::unordered_set; using std::vector; using sigrok::Channel; @@ -71,7 +72,7 @@ Channels::Channels(Session &session, QWidget *parent) : map, shared_ptr > signal_map; shared_lock lock(session_.signals_mutex()); - const vector< shared_ptr > &sigs(session_.signals()); + const unordered_set< shared_ptr > &sigs(session_.signals()); for (const shared_ptr &sig : sigs) signal_map[sig->channel()] = sig; diff --git a/pv/session.cpp b/pv/session.cpp index 751afb30..e0096e9c 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -60,6 +60,7 @@ using std::mutex; using std::set; using std::shared_ptr; using std::string; +using std::unordered_set; using std::vector; using sigrok::Analog; @@ -257,7 +258,7 @@ boost::shared_mutex& Session::signals_mutex() const return signals_mutex_; } -const vector< shared_ptr >& Session::signals() const +const unordered_set< shared_ptr >& Session::signals() const { return signals_; } @@ -405,7 +406,7 @@ void Session::update_signals(shared_ptr device) } assert(signal); - signals_.push_back(signal); + signals_.insert(signal); } } diff --git a/pv/session.hpp b/pv/session.hpp index d71b1d6c..d17c9dc3 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #ifdef _WIN32 @@ -117,7 +118,8 @@ public: boost::shared_mutex& signals_mutex() const; - const std::vector< std::shared_ptr >& signals() const; + const std::unordered_set< std::shared_ptr >& + signals() const; #ifdef ENABLE_DECODE bool add_decoder(srd_decoder *const dec); @@ -171,7 +173,7 @@ private: capture_state capture_state_; mutable boost::shared_mutex signals_mutex_; - std::vector< std::shared_ptr > signals_; + std::unordered_set< std::shared_ptr > signals_; mutable std::mutex data_mutex_; std::shared_ptr logic_data_; diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 92f64f5b..20fa19fe 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -45,6 +45,7 @@ using std::set; using std::shared_ptr; using std::string; using std::thread; +using std::unordered_set; using std::vector; using Glib::VariantBase; @@ -92,7 +93,8 @@ bool StoreSession::start() session_.get_data(); shared_lock lock(session_.signals_mutex()); - const vector< shared_ptr > &sigs(session_.signals()); + const unordered_set< shared_ptr > &sigs( + session_.signals()); // Check we have logic data if (data_set.empty() || sigs.empty()) { diff --git a/pv/view/decodetrace.cpp b/pv/view/decodetrace.cpp index f423b21e..4af65f54 100644 --- a/pv/view/decodetrace.cpp +++ b/pv/view/decodetrace.cpp @@ -66,6 +66,7 @@ using std::min; using std::pair; using std::shared_ptr; using std::tie; +using std::unordered_set; using std::vector; namespace pv { @@ -704,7 +705,12 @@ QComboBox* DecodeTrace::create_channel_selector( assert(dec); shared_lock lock(session_.signals_mutex()); - const vector< shared_ptr > &sigs(session_.signals()); + const auto &sigs(session_.signals()); + + vector< shared_ptr > sig_list(sigs.begin(), sigs.end()); + std::sort(sig_list.begin(), sig_list.end(), + [](const shared_ptr &a, const shared_ptr b) { + return a->name().compare(b->name()) < 0; }); assert(decoder_stack_); const auto channel_iter = dec->channels().find(pdch); @@ -716,16 +722,15 @@ QComboBox* DecodeTrace::create_channel_selector( if (channel_iter == dec->channels().end()) selector->setCurrentIndex(0); - for(size_t i = 0; i < sigs.size(); i++) { - const shared_ptr s(sigs[i]); + for (const shared_ptr &s : sig_list) { assert(s); - if (dynamic_pointer_cast(s) && s->enabled()) { selector->addItem(s->name(), qVariantFromValue((void*)s.get())); if ((*channel_iter).second == s) - selector->setCurrentIndex(i + 1); + selector->setCurrentIndex( + selector->count() - 1); } } @@ -739,7 +744,7 @@ void DecodeTrace::commit_decoder_channels(shared_ptr &dec map > channel_map; shared_lock lock(session_.signals_mutex()); - const vector< shared_ptr > &sigs(session_.signals()); + const unordered_set< shared_ptr > &sigs(session_.signals()); for (const ChannelSelector &s : channel_selectors_) { diff --git a/pv/view/view.cpp b/pv/view/view.cpp index 4d823a02..f6c41843 100644 --- a/pv/view/view.cpp +++ b/pv/view/view.cpp @@ -297,7 +297,7 @@ void View::set_scale_offset(double scale, double offset) set< shared_ptr > View::get_visible_data() const { shared_lock lock(session().signals_mutex()); - const vector< shared_ptr > &sigs(session().signals()); + const unordered_set< shared_ptr > &sigs(session().signals()); // Make a set of all the visible data objects set< shared_ptr > visible_data; @@ -683,7 +683,7 @@ void View::signals_changed() signal_map; shared_lock lock(session_.signals_mutex()); - const vector< shared_ptr > &sigs(session_.signals()); + const unordered_set< shared_ptr > &sigs(session_.signals()); for (const shared_ptr &sig : sigs) signal_map[sig->channel()] = sig;