summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qset.h13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index 08b38a08c2..7ded120ab7 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -340,13 +340,14 @@ Q_INLINE_TEMPLATE bool QSet<T>::intersects(const QSet<T> &other) const
template <class T>
Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other)
{
- QSet<T> copy1(*this);
- QSet<T> copy2(other);
- typename QSet<T>::const_iterator i = copy1.constEnd();
- while (i != copy1.constBegin()) {
- --i;
- if (copy2.contains(*i))
+ if (&other == this) {
+ clear();
+ } else {
+ auto i = other.constEnd();
+ while (i != other.constBegin()) {
+ --i;
remove(*i);
+ }
}
return *this;
}