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>
This commit is contained in:
Mårten Nordheim 2020-11-19 10:52:41 +01:00 committed by Qt Cherry-pick Bot
parent 9f0491b8c6
commit 7b2b4bb5d0

View File

@ -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);