diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2024-01-18 11:40:09 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2024-01-20 08:55:06 +0000 |
commit | 92acc94fa98d19929d28feb5d543acf8c50c2290 (patch) | |
tree | 7f98da205d736db7dae637f89f0092674dd8acc6 /src/corelib/tools/qset.h | |
parent | fd6dc2e9e7ce12d73e095a70b3259ea649f4a62d (diff) |
Optimize QSet::unite
Done similar to intersect. This also improves one test, as we get one less detach, and makes it consistent with other results.
Change-Id: I4d08bf43e750c758b363f8e4fe1fe312a7a0cde4
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qset.h')
-rw-r--r-- | src/corelib/tools/qset.h | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index b75f19f242..7330b5e91c 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -228,10 +228,13 @@ Q_INLINE_TEMPLATE void QSet<T>::reserve(qsizetype asize) { q_hash.reserve(asize) template <class T> Q_INLINE_TEMPLATE QSet<T> &QSet<T>::unite(const QSet<T> &other) { - if (!q_hash.isSharedWith(other.q_hash)) { - for (const T &e : other) - insert(e); - } + if (q_hash.isSharedWith(other.q_hash)) + return *this; + QSet<T> tmp = other; + if (size() < other.size()) + swap(tmp); + for (const auto &e : std::as_const(tmp)) + insert(e); return *this; } |