From 5456fd5717feb3133cc22aef80cc858d1cb0551b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 26 Feb 2017 18:19:50 +0100 Subject: [PATCH] make Selection::set (TrackViewList*) more efficient and emit less PI::Change signals --- gtk2_ardour/selection.cc | 49 +++++++++++++--------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/gtk2_ardour/selection.cc b/gtk2_ardour/selection.cc index 23abfa17c3..ab26bfd48a 100644 --- a/gtk2_ardour/selection.cc +++ b/gtk2_ardour/selection.cc @@ -830,46 +830,29 @@ Selection::set (const TrackViewList& track_list) { clear_objects(); //enforce object/range exclusivity - PresentationInfo::ChangeSuspender cs; - - if (!tracks.empty()) { - /* cannot use set::operator== (set const &) here, because - * apparently the ordering used within 2 sets is not - * necessarily the same. - */ - - if (tracks.size() == track_list.size()) { - bool missing = false; - - for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) { - if (dynamic_cast (*x)) { - continue; - } - if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) { - missing = true; - } - } + TrackViewList to_be_added; + TrackViewList to_be_removed; - if (!missing) { - /* already same selection: nothing to do */ - return; - } + for (TrackViewList::const_iterator x = tracks.begin(); x != tracks.end(); ++x) { + if (find (track_list.begin(), track_list.end(), *x) == track_list.end()) { + to_be_removed.push_back (*x); } + } - /* argument is different from existing selection */ - - for (TrackViewList::iterator x = tracks.begin(); x != tracks.end(); ++x) { - if (dynamic_cast (*x)) { - continue; - } - (*x)->set_selected (false); + for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) { + if (dynamic_cast (*x)) { + continue; + } + if (find (tracks.begin(), tracks.end(), *x) == tracks.end()) { + to_be_added.push_back (*x); } - - tracks.clear (); } - add (track_list); + PresentationInfo::ChangeSuspender cs; + remove (to_be_removed); + add (to_be_added); + } void -- 2.30.2