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>
This commit is contained in:
Marc Mutz 2016-01-04 17:40:55 +01:00
parent e13544f186
commit 15238e91eb

View File

@ -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())