From 33693473d4bf6b28bee2d5fe740633d6867c26af Mon Sep 17 00:00:00 2001 From: Sze Howe Koh Date: Mon, 25 Sep 2017 19:17:02 +0800 Subject: Remove unnecessary copying in QSet::subtract() Task-number: QTBUG-42810 Change-Id: I5d4793a12b078e34bea034b4500e270d42609de0 Reviewed-by: Thiago Macieira --- src/corelib/tools/qset.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') 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::intersects(const QSet &other) const template Q_INLINE_TEMPLATE QSet &QSet::subtract(const QSet &other) { - QSet copy1(*this); - QSet copy2(other); - typename QSet::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; } -- cgit v1.2.3