diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2022-01-07 09:10:51 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2022-01-12 01:03:15 +0000 |
| commit | 66a183298a8ff3d51da02f25ffe5eeea0ea76862 (patch) | |
| tree | 52d47b2261eccd02611496c3c7d38edfa7d73bc5 /src/plugins/platforms/wasm/qwasmcursor.cpp | |
| parent | d4611ba3a5b46ee790e6c790ef6c3d771d3507ee (diff) | |
QPointingDevice: avoid double lookup in Private::pointById()
Use the newly-added try_emplace() function, to work around Qt's
associative container's broken insert() behavior (which is
equivalent to STL's insert_or_assign()), forcing either a double
lookup:
auto it = c.find(key); // lookup 1
if (it == c.end())
c.insert(key, ~~~); // lookup 2
or the usual size-check trick:
const auto oldSize = c.size();
auto &e = c[key];
if (c.size() != oldSize) {
// newly inserted
onto any lookup-or-initialize-like code. try_emplace beats them
both in terms of efficiency and readability.
Pick-to: 6.3
Change-Id: I4c52d2f2d5175991db4931d29c688de125f5b032
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/plugins/platforms/wasm/qwasmcursor.cpp')
0 files changed, 0 insertions, 0 deletions
