From f08f28548ae04f89bd7fd24673c1369c96786e3d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 28 Jan 2022 00:48:59 +0100 Subject: [PATCH] QFlatMap: implement mutable op[] via try_emplace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit De-duplicates code. Pick-to: 6.3 Change-Id: Id7841a0717cd66bd56d489e6d2630e9eeb284316 Reviewed-by: Fabian Kosmale Reviewed-by: Jörg Bornemann --- src/corelib/tools/qflatmap_p.h | 14 ++------------ 1 file 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