summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2020-11-19 10:52:41 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2020-11-21 23:17:23 +0000
commitf518c1efe6ce61b6403a221d26d63d3f0745937f (patch)
tree69550678fa435ef24f504999eda8949b93c8cee5
parent64319ae45ebbd1bfb3fb741756c924e445516ac7 (diff)
QCache: fix accidental pessimization
By unconditionally removing the existing entry we never hit the if (result.initialized) branch. Change it to only remove the existing entry if we don't plan on inserting. Task-number: QTBUG-88183 Change-Id: If4e7ebac23aa63d4b9d4b0a22882dd7d90a58e8b Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit f08492c6fd9818c7d80b1725355453e179b4d85b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/tools/qcache.h3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h
index 4cfe4a4a48..7c065a8806 100644
--- a/src/corelib/tools/qcache.h
+++ b/src/corelib/tools/qcache.h
@@ -236,10 +236,9 @@ public:
bool insert(const Key &key, T *object, qsizetype cost = 1)
{
- remove(key);
-
if (cost > mx) {
delete object;
+ remove(key);
return false;
}
trim(mx - cost);