QCache3Q: avoid double-lookups in insert()
The contains() call is unnecessary, because QHash::op[] will return a
value-initialized value (iow: a nullptr) when the key did not, yet,
exist. The old code unconditionally dereferenced the value if the key
existed, so the class must have the invariant that the values in
lookup_ must all be non-nullptr. So we can use a nullptr result as an
indication that the element didn't exist, yet. We don't even need the
usual size-check, though I've added it to assert the above analysis is
actually correct.
So replace the contains/op[] pair with just one op[] call, storing the
result in a reference for the case when we need to initialize the
value.
link_front() does not touch lookup_, so we can swap it with the op[]
call in the newly-inserted case.
Amends e071be7ff80373b3f4fb523393c9875a8c00e0af.
Pick-to: 6.9 6.8
Change-Id: Ie4153ed4e94d4fbd8a92387196295560c5028095
Reviewed-by: Magdalena Stojek <magdalena.stojek@qt.io>
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>