diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-10-12 22:47:13 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-11-28 21:34:23 +0000 |
commit | 9f591b3b6ca4d3c0de234f04bb9a2deb8d784170 (patch) | |
tree | 216aaf7442282625b4ecc5b2e7665c81ccee2624 /src/corelib | |
parent | 4efa50a5e37497bc3a3dd30f27db7d8100e3f6a5 (diff) |
QVector: prevent resize() from shedding capacity
...even if reserve() hasn't been called before.
[ChangeLog][QtCore][QVector] resize() will no longer shrink the
capacity. That means resize(0) now reliably preserves capacity().
Task-number: QTBUG-39293
Done-with: Robin Burchell <robin.burchell@viroteck.net>
Change-Id: Ie7e4e597126832990b6cfb83bba875c3963b143e
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qvector.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qvector.h | 3 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp index 0fcba3c0c4..f1cf23cc6a 100644 --- a/src/corelib/tools/qvector.cpp +++ b/src/corelib/tools/qvector.cpp @@ -384,6 +384,9 @@ initialized with a \l{default-constructed value}. If \a size is less than the current size, elements are removed from the end. + Since Qt 5.6, resize() doesn't shrink the capacity anymore. + To shed excess capacity, use squeeze(). + \sa size() */ diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 890dbd317d..3ce33fb477 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -406,9 +406,6 @@ void QVector<T>::resize(int asize) if (asize > oldAlloc) { // there is not enough space newAlloc = asize; opt = QArrayData::Grow; - } else if (!d->capacityReserved && asize < d->size && asize < (oldAlloc >> 1)) { // we want to shrink - newAlloc = asize; - opt = QArrayData::Grow; } else { newAlloc = oldAlloc; } |