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
Change-Id: I30394da43a5e93b7bd41ef9ce9c7aea044523c30
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit aa8e8e94b99dfff8613bcbcc8ac6de5d0d8bcb12)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-06-05 15:49:57 +02:00 committed by Qt Cherry-pick Bot
parent 8050a66a8d
commit 9d6543ea40

View File

@ -316,25 +316,16 @@ QPixmap *QPMCache::object(const QPixmapCache::Key &key) const
bool QPMCache::insert(const QString& key, const QPixmap &pixmap, int cost) 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 for the same key we add already a pixmap we should delete it
if (cacheKey.d) remove(key);
QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey);
//we create a new key the old one has been removed // this will create a new key; the old one has been removed
cacheKey = createKey(); auto k = insert(pixmap, cost);
if (k.isValid()) {
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost); cacheKeys[key] = std::move(k);
if (success) { return true;
if (!theid) {
theid = startTimer(flush_time);
t = false;
}
} else {
//Insertion failed we released the new allocated key
cacheKeys.remove(key);
} }
return success; return false;
} }
QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost) QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)