QPixmapCache: simplify remove(QString)

The previous code used `cacheKey` as the name of an iterator, which
made the code hard to understand.

Instead of renaming that to the more idiomatic `it`, use QHash::take()
to get an actual `cacheKey` back, and then delegate to
QPMCache::remove(QPixmapCache::Key) for the actual removal.

Pick-to: 6.6 6.5 6.2
Task-number: QTBUG-112200
Change-Id: I9311c19f12a05cad694702672f17ae19ba339b04
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Marc Mutz 2023-06-12 12:20:34 +02:00
parent 8cad4c2903
commit c2bcba93a6
1 changed files with 2 additions and 7 deletions

View File

@ -352,13 +352,8 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
bool QPMCache::remove(const QString &key)
{
auto cacheKey = cacheKeys.constFind(key);
//The key was not in the cache
if (cacheKey == cacheKeys.constEnd())
return false;
const bool result = QCache<QPixmapCache::Key, QPixmapCacheEntry>::remove(cacheKey.value());
cacheKeys.erase(cacheKey);
return result;
const auto cacheKey = cacheKeys.take(key);
return cacheKey.isValid() && remove(cacheKey);
}
bool QPMCache::remove(const QPixmapCache::Key &key)