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>
This commit is contained in:
Marc Mutz 2015-10-12 22:47:13 +02:00
parent 4efa50a5e3
commit 9f591b3b6c
2 changed files with 3 additions and 3 deletions

View File

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

View File

@ -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;
}