[PATCH 1/3] Playlist performance: maintain a multihash mapping Track -> Item

Nanno Langstraat langstr at gmail.com
Mon Feb 1 00:09:06 CET 2010


This is still just building infrastructure.
---
 src/playlist/PlaylistModel.cpp |    5 +++++
 src/playlist/PlaylistModel.h   |    2 ++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/playlist/PlaylistModel.cpp b/src/playlist/PlaylistModel.cpp
index 2de3707..c000295 100644
--- a/src/playlist/PlaylistModel.cpp
+++ b/src/playlist/PlaylistModel.cpp
@@ -112,6 +112,7 @@ Playlist::Model::Model( QObject *parent )
             Item* i = new Item( track );
             m_items.append( i );
             m_itemIds.insert( i->id(), i );
+            m_TrackToItems.insert( i->track(), i );
         }
     }
 
@@ -775,6 +776,8 @@ Playlist::Model::insertTracksCommand( const InsertCmdList& cmds )
         Item* newitem = new Item( track );
         m_items.insert( ic.second, newitem );
         m_itemIds.insert( newitem->id(), newitem );
+        m_TrackToItems.insert( newitem->track(), newitem );
+
         newIds.append( newitem->id() );
     }
     endInsertRows();
@@ -880,6 +883,7 @@ Playlist::Model::removeTracksCommand( const RemoveCmdList& cmds )
 
         m_items.removeAll( item );
         m_itemIds.remove( item->id() );
+        m_TrackToItems.remove( item->track(), item );
         delete item;
 
         endRemoveRows();    // QAbstractItemModel
@@ -922,6 +926,7 @@ void Playlist::Model::clearCommand()
     qDeleteAll( m_items );
     m_items.clear();
     m_itemIds.clear();
+    m_TrackToItems.clear();
     endRemoveRows();
 
     m_activeRow = -1;
diff --git a/src/playlist/PlaylistModel.h b/src/playlist/PlaylistModel.h
index 743db25..d919d41 100644
--- a/src/playlist/PlaylistModel.h
+++ b/src/playlist/PlaylistModel.h
@@ -29,6 +29,7 @@
 
 #include <QAbstractListModel>
 #include <QHash>
+#include <QMultiHash>
 #include "QList_Imitation_FastIndexOf.h"
 
 #include <KLocale>
@@ -169,6 +170,7 @@ class AMAROK_EXPORT Model : public QAbstractListModel, public Meta::Observer, pu
         PlaylistItems m_items; //! list of playlist items.
             // 'm_items' keeps the "manual" order; sorting happens in the proxy models.
         QHash<quint64, Item*> m_itemIds; //! maps track id's to items
+        QMultiHash<Meta::TrackPtr, Item*> m_TrackToItems; //! maps track pointers to playlist items
 
         int m_activeRow;                 //! the row being played
 
-- 
1.7.0.4


--------------050205060600030001000806
Content-Type: text/x-patch;
 name="0002-Playlist-performance-finally-start-using-the-infrast.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0002-Playlist-performance-finally-start-using-the-infrast.pa";
 filename*1="tch"



More information about the Amarok-devel mailing list