]> sigrok.org Git - pulseview.git/commitdiff
Session: Store signals_ in an unordered_set
authorJoel Holdsworth <redacted>
Sat, 28 Mar 2015 12:10:14 +0000 (12:10 +0000)
committerJoel Holdsworth <redacted>
Thu, 28 May 2015 14:59:04 +0000 (15:59 +0100)
pv/popups/channels.cpp
pv/session.cpp
pv/session.hpp
pv/storesession.cpp
pv/view/decodetrace.cpp
pv/view/view.cpp

index 61a8aee071b382e9fc626a89ec08e2cda7975213..3d209e84bb15a9350cc7445966c15fbde81f3b08 100644 (file)
@@ -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<Channel>, shared_ptr<Signal> > signal_map;
 
        shared_lock<shared_mutex> lock(session_.signals_mutex());
-       const vector< shared_ptr<Signal> > &sigs(session_.signals());
+       const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
 
        for (const shared_ptr<Signal> &sig : sigs)
                signal_map[sig->channel()] = sig;
index 751afb30bd746abb7fe95fa20a35dcce9a232149..e0096e9cd1245c3b233e65c6afc529b004ac9f91 100644 (file)
@@ -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<view::Signal> >& Session::signals() const
+const unordered_set< shared_ptr<view::Signal> >& Session::signals() const
 {
        return signals_;
 }
@@ -405,7 +406,7 @@ void Session::update_signals(shared_ptr<Device> device)
                        }
 
                        assert(signal);
-                       signals_.push_back(signal);
+                       signals_.insert(signal);
                }
 
        }
index d71b1d6cec3f267bab7044b52dd69d375a1987a3..d17c9dc364205344d157e7c271601cb5c6e9c5a7 100644 (file)
@@ -27,6 +27,7 @@
 #include <set>
 #include <string>
 #include <thread>
+#include <unordered_set>
 #include <vector>
 
 #ifdef _WIN32
@@ -117,7 +118,8 @@ public:
 
        boost::shared_mutex& signals_mutex() const;
 
-       const std::vector< std::shared_ptr<view::Signal> >& signals() const;
+       const std::unordered_set< std::shared_ptr<view::Signal> >&
+               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<view::Signal> > signals_;
+       std::unordered_set< std::shared_ptr<view::Signal> > signals_;
 
        mutable std::mutex data_mutex_;
        std::shared_ptr<data::Logic> logic_data_;
index 92f64f5ba12a328b56bad5728ec8db14c3000b82..20fa19fef41d744d6da784620884a84256bdc30f 100644 (file)
@@ -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<shared_mutex> lock(session_.signals_mutex());
-       const vector< shared_ptr<view::Signal> > &sigs(session_.signals());
+       const unordered_set< shared_ptr<view::Signal> > &sigs(
+               session_.signals());
 
        // Check we have logic data
        if (data_set.empty() || sigs.empty()) {
index f423b21ef9a009caa04202109882666e2b6d0fb4..4af65f5488ec2b60f0f347e18389d307c0d04e9c 100644 (file)
@@ -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<shared_mutex> lock(session_.signals_mutex());
-       const vector< shared_ptr<Signal> > &sigs(session_.signals());
+       const auto &sigs(session_.signals());
+
+       vector< shared_ptr<Signal> > sig_list(sigs.begin(), sigs.end());
+       std::sort(sig_list.begin(), sig_list.end(),
+               [](const shared_ptr<Signal> &a, const shared_ptr<Signal> 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<view::Signal> s(sigs[i]);
+       for (const shared_ptr<view::Signal> &s : sig_list) {
                assert(s);
-
                if (dynamic_pointer_cast<LogicSignal>(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<data::decode::Decoder> &dec
        map<const srd_channel*, shared_ptr<LogicSignal> > channel_map;
 
        shared_lock<shared_mutex> lock(session_.signals_mutex());
-       const vector< shared_ptr<Signal> > &sigs(session_.signals());
+       const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
 
        for (const ChannelSelector &s : channel_selectors_)
        {
index 4d823a02b204c32daade5e96a586b44709b4d2eb..f6c418433021d9007400b7a407cfe6e7289a6487 100644 (file)
@@ -297,7 +297,7 @@ void View::set_scale_offset(double scale, double offset)
 set< shared_ptr<SignalData> > View::get_visible_data() const
 {
        shared_lock<shared_mutex> lock(session().signals_mutex());
-       const vector< shared_ptr<Signal> > &sigs(session().signals());
+       const unordered_set< shared_ptr<Signal> > &sigs(session().signals());
 
        // Make a set of all the visible data objects
        set< shared_ptr<SignalData> > visible_data;
@@ -683,7 +683,7 @@ void View::signals_changed()
                signal_map;
 
        shared_lock<shared_mutex> lock(session_.signals_mutex());
-       const vector< shared_ptr<Signal> > &sigs(session_.signals());
+       const unordered_set< shared_ptr<Signal> > &sigs(session_.signals());
 
        for (const shared_ptr<Signal> &sig : sigs)
                signal_map[sig->channel()] = sig;