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>bb10
parent
fd6dc2e9e7
commit
92acc94fa9
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -856,7 +856,7 @@ void tst_QSet::setOperationsOnEmptySet()
|
|||
|
||||
empty.unite(nonEmpty);
|
||||
QCOMPARE(empty, nonEmpty);
|
||||
QVERIFY(empty.isDetached());
|
||||
QVERIFY(!empty.isDetached());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue