diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index d403a0416e..deccaaf387 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -229,13 +229,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 2bb300a0c5..34e9334296 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -898,7 +898,7 @@ void tst_QSet::setOperationsOnEmptySet() empty.unite(nonEmpty); QCOMPARE(empty, nonEmpty); - QVERIFY(!empty.isDetached()); + QVERIFY(empty.isDetached()); } } @@ -1312,11 +1312,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));