summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-01-28 00:48:59 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-29 13:40:58 +0000
commit313225faf472a4676707e891eba4e73ae6c5587f (patch)
tree4da94b14e638712a5ea5a90073956160527af419
parent0adc495c7291165f24209ca54ee39958a5356ac6 (diff)
QFlatMap: implement mutable op[] via try_emplace()
De-duplicates code. Change-Id: Id7841a0717cd66bd56d489e6d2630e9eeb284316 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io> (cherry picked from commit f08f28548ae04f89bd7fd24673c1369c96786e3d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/tools/qflatmap_p.h14
1 files changed, 2 insertions, 12 deletions
diff --git a/src/corelib/tools/qflatmap_p.h b/src/corelib/tools/qflatmap_p.h
index 3be517a483..d9bcf08c9d 100644
--- a/src/corelib/tools/qflatmap_p.h
+++ b/src/corelib/tools/qflatmap_p.h
@@ -651,22 +651,12 @@ public:
T &operator[](const Key &key)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.keys.insert(toKeysIterator(it), key);
- return *c.values.insert(toValuesIterator(it), T());
- }
- return it.value();
+ return try_emplace(key).first.value();
}
T &operator[](Key &&key)
{
- auto it = lower_bound(key);
- if (it == end() || key_compare::operator()(key, it.key())) {
- c.keys.insert(toKeysIterator(it), key);
- return *c.values.insert(toValuesIterator(it), T());
- }
- return it.value();
+ return try_emplace(std::move(key)).first.value();
}
T operator[](const Key &key) const