diff options
Diffstat (limited to 'src/gui/image/qpixmapcache.cpp')
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 19 |
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) |