diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-06-05 15:49:57 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-06-20 15:25:13 +0200 |
commit | aa8e8e94b99dfff8613bcbcc8ac6de5d0d8bcb12 (patch) | |
tree | 55ca63f3878c4938c97767da4c9737d744dd680a | |
parent | c2bcba93a67ed980021304c3bbca5556b4cc3add (diff) |
QPixmapCache: DRY insert()
Implement insert(QString, QPixmap) in terms of insert(QPixmap) to
avoid duplicating code and to separate concerns: insert(QString,
QPixmap) is now only dealing with the cacheKeys, insert(QPixmap) is
only concerned with the Key-based lookup.
Task-number: QTBUG-112200
Pick-to: 6.6 6.5 6.2
Change-Id: I30394da43a5e93b7bd41ef9ce9c7aea044523c30
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/gui/image/qpixmapcache.cpp | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/gui/image/qpixmapcache.cpp b/src/gui/image/qpixmapcache.cpp index 6c62bae69e..6cc5fd28a3 100644 --- a/src/gui/image/qpixmapcache.cpp +++ b/src/gui/image/qpixmapcache.cpp @@ -316,25 +316,16 @@ QPixmap *QPMCache::object(const QPixmapCache::Key &key) const bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) { - QPixmapCache::Key &cacheKey = cacheKeys[key]; //If for the same key we add already a pixmap we should delete it - if (cacheKey.d) - QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey); + remove(key); - //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) { - if (!theid) { - theid = startTimer(flush_time); - t = false; - } - } else { - //Insertion failed we released the new allocated key - cacheKeys.remove(key); + // this will create a new key; the old one has been removed + auto k = insert(pixmap, cost); + if (k.isValid()) { + cacheKeys[key] = std::move(k); + return true; } - return success; + return false; } QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) |