make Selection::set (TrackViewList*) more efficient and emit less PI::Change signals
authorPaul Davis <paul@linuxaudiosystems.com>
Sun, 26 Feb 2017 17:19:50 +0000 (18:19 +0100)
committerPaul Davis <paul@linuxaudiosystems.com>
Sun, 26 Feb 2017 17:24:56 +0000 (18:24 +0100)
gtk2_ardour/selection.cc

index 23abfa17c35cbc375529f89e83750d6ed04c10f9..ab26bfd48ab484a99e2c1f6cc63ab8aaa90e3a07 100644 (file)
@@ -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<T>::operator== (set<T> 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<VCATimeAxisView*> (*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<VCATimeAxisView*> (*x)) {
-                               continue;
-                       }
-                       (*x)->set_selected (false);
+       for (TrackViewList::const_iterator x = track_list.begin(); x != track_list.end(); ++x) {
+               if (dynamic_cast<VCATimeAxisView*> (*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