[system/dolphin] src: kitemviews: take the room for the values of an item at once

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 6a520e646502a591a9e99245b19f12a9b324787d by Méven Car.
Committed on 29/07/2026 at 20:09.
Pushed by meven into branch 'master'.

kitemviews: take the room for the values of an item at once

The values of an item are inserted one role at a time, and the vector behind them grows into each pair
as it arrives: for the five roles of a details view it ends up with room for eight, having left the
room for one, two and four behind it.

Every role of the view is a pair the item is about to hold, give or take the few that only some items
have, so the room is taken once before the roles are inserted. For 100000 items of five roles that is
336 bytes an item rather than 512.

M  +1    -0    src/kitemviews/kfileitemmodel.cpp
M  +4    -0    src/smallhash.h

https://invent.kde.org/system/dolphin/-/commit/6a520e646502a591a9e99245b19f12a9b324787d

diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp
index 542c32ae6d..c358773c21 100644
--- a/src/kitemviews/kfileitemmodel.cpp
+++ b/src/kitemviews/kfileitemmodel.cpp
@@ -2214,6 +2214,7 @@ SmallHash KFileItemModel::retrieveData(const KFileItem &item, const ItemData *pa
     // KFileItem::iconName() can be very expensive if the MIME-type is unknown
     // and hence will be retrieved asynchronously by KFileItemModelRolesUpdater.
     SmallHash data;
+    data.reserve(m_roles.count());
 
     const bool isDir = item.isDir();
     if (m_requestRole[IsDirRole] && isDir) {
diff --git a/src/smallhash.h b/src/smallhash.h
index db8a2d870b..7c58f112e1 100644
--- a/src/smallhash.h
+++ b/src/smallhash.h
@@ -47,6 +47,10 @@ public:
     {
         (*this)[key] = value;
     }
+    void reserve(int size)
+    {
+        m_data.reserve(size);
+    }
     QVariant operator[](const QByteArray &key) const
     {
         return value(key);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.