diff options
| author | Frank Reininghaus <[email protected]> | 2014-02-07 10:22:17 +0100 |
|---|---|---|
| committer | Frank Reininghaus <[email protected]> | 2014-02-07 10:22:17 +0100 |
| commit | bb22ac0a4745b63ac02d72d176b93bc3f2b84ca0 (patch) | |
| tree | ef31f8aac2d87e57bd855a0b49b63315ac9a6425 /src/kitemviews/kfileitemmodel.h | |
| parent | 564dcb08fd0f6fe23d55bd8216af4e5295abf099 (diff) | |
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
Diffstat (limited to 'src/kitemviews/kfileitemmodel.h')
| -rw-r--r-- | src/kitemviews/kfileitemmodel.h | 11 |
1 files changed, 8 insertions, 3 deletions
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<ItemData*> m_itemData; - QHash<KUrl, int> 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<KUrl, int> m_items; KFileItemModelFilter m_filter; QHash<KFileItem, ItemData*> m_filteredItems; // Items that got hidden by KFileItemModel::setNameFilter() |
