diff options
author | Mårten Nordheim <marten.nordheim@qt.io> | 2021-01-12 17:25:03 +0100 |
---|---|---|
committer | Mårten Nordheim <marten.nordheim@qt.io> | 2021-01-14 10:00:01 +0000 |
commit | d2e2d0d3a6249ccbc17ec92acb32fec9a0d71807 (patch) | |
tree | 30238f5e8aa22f0d11a884700df13af71ecf8e46 /src/corelib | |
parent | cb4f853cb05bd57c0a00d9ca41b7e30bdd13bf9a (diff) |
QCache: when overwriting, store the new cost instead of the delta
The delta was clearly intended to be used on the total (and still is)
but it also wound up getting stored in the cache, which wouldn't be a
big problem unless the object was removed, in which case we could
incidentally 'free up more space' than intended.
Pick-to: 6.0
Change-Id: Ib2b0f072d30da6d16a93dce60e4c5f6080c109fc
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qcache.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 41cf9abc46..8a341c8555 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -245,8 +245,9 @@ public: auto result = d.findOrInsert(key); Node *n = result.it.node(); if (result.initialized) { - cost -= n->value.cost; + auto prevCost = n->value.cost; result.it.node()->emplace(object, cost); + cost -= prevCost; relink(key); } else { Node::createInPlace(n, key, object, cost); |