summaryrefslogtreecommitdiffstats
path: root/src/gui/image/qpixmapcache.cpp
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-10 12:45:49 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-11-10 16:14:51 +0000
commit467b15a20c3d6eb611ea5f6ccffd5fc0df81b0c4 (patch)
tree1bff11fa019cebd2242c856301b7bd28462a9f6c /src/gui/image/qpixmapcache.cpp
parent5cff7d2b679d48a247b4630cb9e3d5b04fab0b55 (diff)
Improve use of QHash to minimize double hashing
Avoid looking up by key twice in a row in various locations, but instead using iterators and index lookup. Change-Id: I61a079115199ab9c041ad3a26d36b45ee3f775e0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui/image/qpixmapcache.cpp')
-rw-r--r--src/gui/image/qpixmapcache.cpp19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp
index 6d03332367..73448943e1 100644
--- a/src/gui/image/qpixmapcache.cpp
+++ b/src/gui/image/qpixmapcache.cpp
@@ -324,26 +324,23 @@ QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost)
{
- QPixmapCache::Key cacheKey;
- QPixmapCache::Key oldCacheKey = cacheKeys.value(key);
+ QPixmapCache::Key &cacheKey = cacheKeys[key];
//If for the same key we add already a pixmap we should delete it
- if (oldCacheKey.d) {
- QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(oldCacheKey);
- cacheKeys.remove(key);
- }
+ if (cacheKey.d)
+ QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
//we create a new key the old one has been removed
cacheKey = createKey();
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
if (success) {
- cacheKeys.insert(key, cacheKey);
if (!theid) {
theid = startTimer(flush_time);
t = false;
}
} else {
//Insertion failed we released the new allocated key
+ cacheKeys.remove(key);
releaseKey(cacheKey);
}
return success;
@@ -389,12 +386,12 @@ bool QPMCache::replace(const QPixmapCache::Key &key, const QPixmap &pixmap, int
bool QPMCache::remove(const QString &key)
{
- QPixmapCache::Key cacheKey = cacheKeys.value(key);
+ auto cacheKey = cacheKeys.constFind(key);
//The key was not in the cache
- if (!cacheKey.d)
+ if (cacheKey == cacheKeys.constEnd())
return false;
- cacheKeys.remove(key);
- return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
+ cacheKeys.erase(cacheKey);
+ return QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey.value());
}
bool QPMCache::remove(const QPixmapCache::Key &key)