[vlmc-devel] MarkerManager: Use QSet instead of QList

Yikai Lu git at videolan.org
Thu Jul 13 14:35:14 CEST 2017


vlmc | branch: master | Yikai Lu <luyikei.qmltu at gmail.com> | Thu Jul 13 14:05:49 2017 +0200| [4efa5d52295decc43cd260318e744044791b9b49] | committer: Yikai Lu

MarkerManager: Use QSet instead of QList

On second thought, QSet is faster although it only makes a little difference in this case..

> https://code.videolan.org/videolan/vlmc/commit/4efa5d52295decc43cd260318e744044791b9b49
---

 src/Gui/timeline/MarkerManager.cpp | 15 +++++++--------
 src/Gui/timeline/MarkerManager.h   |  4 ++--
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/Gui/timeline/MarkerManager.cpp b/src/Gui/timeline/MarkerManager.cpp
index 915ee10c..616eae03 100644
--- a/src/Gui/timeline/MarkerManager.cpp
+++ b/src/Gui/timeline/MarkerManager.cpp
@@ -43,14 +43,13 @@ MarkerManager::addMarker( quint64 pos )
 void
 MarkerManager::moveMarker( quint64 from, quint64 to )
 {
-    for ( int i = 0; i < m_markers.size(); ++i )
+    auto it = m_markers.find( from );
+    if ( it != m_markers.end() )
     {
-        if ( m_markers[i] == from )
-        {
-            m_markers[i] = to;
-            emit markerMoved( from, to );
-            return;
-        }
+        m_markers.erase( it );
+        m_markers << to;
+        emit markerMoved( from, to );
+        return;
     }
     vlmcCritical() << "Marker at" << from << "doesn't exist.";
 }
@@ -58,7 +57,7 @@ MarkerManager::moveMarker( quint64 from, quint64 to )
 void
 MarkerManager::removeMarker( quint64 pos )
 {
-    bool ret = m_markers.removeOne( pos );
+    bool ret = m_markers.remove( pos );
     if ( ret == true )
         emit markerRemoved( pos );
     else
diff --git a/src/Gui/timeline/MarkerManager.h b/src/Gui/timeline/MarkerManager.h
index a6148dfa..b9fac2f1 100644
--- a/src/Gui/timeline/MarkerManager.h
+++ b/src/Gui/timeline/MarkerManager.h
@@ -24,7 +24,7 @@
 #define MARKERMANAGER_H
 
 #include <QObject>
-#include <QList>
+#include <QSet>
 #include <QVariant>
 
 class MarkerManager : public QObject
@@ -46,7 +46,7 @@ signals:
     void                markerRemoved( quint64 pos );
 
 private:
-    QList<quint64>      m_markers;
+    QSet<quint64>       m_markers;
 };
 
 #endif // MARKERMANAGER_H



More information about the Vlmc-devel mailing list