Details
-
Suggestion
-
Resolution: Done
-
P4: Low
-
4.8.6, 5.3.2
-
None
Description
The function QSet::subtract is slow because of useless copy.
The actual function is :
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)) remove(*i); } return *this; }
I propose a solution without copy :
Q_INLINE_TEMPLATE QSet<T> &QSet<T>::subtract(const QSet<T> &other) { if(&other == this) { this.clear(); } else { for(QSet<T>::iterator it = other.begin(); it != other.end(); ++it) { this.remove(*it); } } return *this; }
Note : the code with corect indentation is in attachment
Attachments
For Gerrit Dashboard: QTBUG-42810 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
206554,5 | Remove unnecessary copying in QSet::subtract() | 5.9 | qt/qtbase | Status: MERGED | +2 | 0 |