diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index cfa8bac6044..3cba1a2b15d 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -232,13 +232,10 @@ Q_INLINE_TEMPLATE void QSet::reserve(qsizetype asize) { q_hash.reserve(asize) template Q_INLINE_TEMPLATE QSet &QSet::unite(const QSet &other) { - if (q_hash.isSharedWith(other.q_hash)) - return *this; - QSet tmp = other; - if (size() < other.size()) - swap(tmp); - for (const auto &e : std::as_const(tmp)) - insert(e); + if (!q_hash.isSharedWith(other.q_hash)) { + for (const T &e : other) + insert(e); + } return *this; } diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index 74e39da0427..4e6dbab9f12 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -920,7 +920,7 @@ void tst_QSet::setOperationsOnEmptySet() empty.unite(nonEmpty); QCOMPARE(empty, nonEmpty); - QVERIFY(!empty.isDetached()); + QVERIFY(empty.isDetached()); } } @@ -1334,11 +1334,9 @@ void tst_QSet::setOperationsPickEquivalentElementsFromLHSContainer_impl() // (unlike other Qt containers, QSet's insertion behavior is STL-compliant): // QVERIFY(lhsCopy.contains(OneL)); - QEXPECT_FAIL("", "QTBUG-132500", Continue); QCOMPARE(lhsCopy.find(OneL)->id, OneL.id); QVERIFY(lhsCopy.contains(TwoL)); - QEXPECT_FAIL("", "QTBUG-132500", Continue); QCOMPARE(lhsCopy.find(TwoL)->id, TwoL.id); QVERIFY(lhsCopy.contains(ThreeL));