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:
parent
4efa50a5e3
commit
9f591b3b6c
@ -384,6 +384,9 @@
|
|||||||
initialized with a \l{default-constructed value}. If \a size is less
|
initialized with a \l{default-constructed value}. If \a size is less
|
||||||
than the current size, elements are removed from the end.
|
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()
|
\sa size()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -406,9 +406,6 @@ void QVector<T>::resize(int asize)
|
|||||||
if (asize > oldAlloc) { // there is not enough space
|
if (asize > oldAlloc) { // there is not enough space
|
||||||
newAlloc = asize;
|
newAlloc = asize;
|
||||||
opt = QArrayData::Grow;
|
opt = QArrayData::Grow;
|
||||||
} else if (!d->capacityReserved && asize < d->size && asize < (oldAlloc >> 1)) { // we want to shrink
|
|
||||||
newAlloc = asize;
|
|
||||||
opt = QArrayData::Grow;
|
|
||||||
} else {
|
} else {
|
||||||
newAlloc = oldAlloc;
|
newAlloc = oldAlloc;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user