diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-01-04 17:40:55 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-02-06 20:06:55 +0000 |
commit | 15238e91eb9e75ce6956852688fd1f0b68f9156a (patch) | |
tree | 523ba69feca31de077a34bd5e7713c901716c188 /src/corelib | |
parent | e13544f1868e38b97173abcf2790addacf3ae265 (diff) |
QList: don't lose reserved capacity in op+= with empty LHS
It is very rare that operator+= is used as operator=.
Most of the time, one op+= is followed by more op+=s.
The old code checked whether *this was empty, and simply
shallow-copied the RHS into the LHS in that case. This
has one severe drawback: a reserve() on the LHS is lost.
Fix by not checking for isEmpty() but for d == &shared_null.
Change-Id: Iff28e496cf24cc93f248449d74012c4f3a87253e
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qlist.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 75d59350f6..5509c3adce 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -935,7 +935,7 @@ template <typename T> Q_OUTOFLINE_TEMPLATE QList<T> &QList<T>::operator+=(const QList<T> &l) { if (!l.isEmpty()) { - if (isEmpty()) { + if (d == &QListData::shared_null) { *this = l; } else { Node *n = (d->ref.isShared()) |