QString/QList: disregard space at front during reserve()

Aligned QString, QList to the new agreed upon behavior

Aligned QList::resize() along the way to be consistent with QString/QBA

Task-number: QTBUG-84320
Change-Id: Ie9d7b4b6ebe54bd373af78d92906144b383bbfe2
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Andrei Golubev 2020-09-02 11:39:13 +02:00
parent b98b7de0da
commit 27fed69d0a
2 changed files with 3 additions and 3 deletions

View File

@ -1167,7 +1167,7 @@ inline QString::~QString() {}
inline void QString::reserve(qsizetype asize)
{
if (d->needsDetach() || asize >= capacity())
if (d->needsDetach() || asize >= capacity() - d.freeSpaceAtBegin())
reallocData(uint(qMax(asize, size())) + 1u, d->detachFlags());
// we're not shared anymore, for sure

View File

@ -467,7 +467,7 @@ inline void QList<T>::resize_internal(qsizetype newSize, Qt::Initialization)
{
Q_ASSERT(newSize >= 0);
if (d->needsDetach() || newSize > capacity()) {
if (d->needsDetach() || newSize > capacity() - d.freeSpaceAtBegin()) {
// must allocate memory
DataPointer detached(Data::allocate(d->detachCapacity(newSize),
d->detachFlags()));
@ -485,7 +485,7 @@ template <typename T>
void QList<T>::reserve(qsizetype asize)
{
// capacity() == 0 for immutable data, so this will force a detaching below
if (asize <= capacity()) {
if (asize <= capacity() - d.freeSpaceAtBegin()) {
if (d->flags() & Data::CapacityReserved)
return; // already reserved, don't shrink
if (!d->isShared()) {