From bb22ac0a4745b63ac02d72d176b93bc3f2b84ca0 Mon Sep 17 00:00:00 2001 From: Frank Reininghaus Date: Fri, 7 Feb 2014 10:22:17 +0100 Subject: Only initialize the hash m_items in KFileItemModel if it is needed Moreover, clear the entire hash if items are added or removed. This saves time and memory when loading a directory, and it fixes problems that might occur if the model is in an inconsistent state, such as crashes that can happen when we try to remove individual items from m_items. BUG: 329494 FIXED-IN: 4.13.0 REVIEW: 115432 --- src/kitemviews/kfileitemmodel.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/kitemviews/kfileitemmodel.h') diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index 15f4b67d3..7cdc160ee 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -130,14 +130,14 @@ public: /** * @return The index for the file-item \a item. -1 is returned if no file-item - * is found or if the file-item is null. The runtime + * is found or if the file-item is null. The amortized runtime * complexity of this call is O(1). */ int index(const KFileItem& item) const; /** * @return The index for the URL \a url. -1 is returned if no file-item - * is found. The runtime complexity of this call is O(1). + * is found. The amortized runtime complexity of this call is O(1). */ int index(const KUrl& url) const; @@ -470,7 +470,12 @@ private: Qt::CaseSensitivity m_caseSensitivity; QList m_itemData; - QHash m_items; // Allows O(1) access for KFileItemModel::index(const KFileItem& item) + + // m_items is a cache for the method index(const KUrl&). If it contains N + // entries, it is guaranteed that these correspond to the first N items in + // the model, i.e., that (for every i between 0 and N - 1) + // m_items.value(fileItem(i).url()) == i + mutable QHash m_items; KFileItemModelFilter m_filter; QHash m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() -- cgit v1.3.1