diff options
author | Sze Howe Koh <szehowe.koh@gmail.com> | 2017-09-25 19:17:02 +0800 |
---|---|---|
committer | Sze Howe Koh <szehowe.koh@gmail.com> | 2017-09-27 00:56:04 +0000 |
commit | 33693473d4bf6b28bee2d5fe740633d6867c26af (patch) | |
tree | 7855b85d5e244c605740be1b103413efd6a958ba /src | |
parent | 35781b358887facf954307b0d6c5958ce089eb72 (diff) |
Remove unnecessary copying in QSet::subtract()
Task-number: QTBUG-42810
Change-Id: I5d4793a12b078e34bea034b4500e270d42609de0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/tools/qset.h | 13 |
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; } |