From 27fed69d0a5842a718e9afe1b82851e2803fc084 Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Wed, 2 Sep 2020 11:39:13 +0200 Subject: [PATCH] QString/QList: disregard space at front during reserve() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/corelib/text/qstring.h | 2 +- src/corelib/tools/qlist.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h index 7daf86a366c..d86d659e754 100644 --- a/src/corelib/text/qstring.h +++ b/src/corelib/text/qstring.h @@ -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 diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index bd593bae55c..e94c108f0ca 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -467,7 +467,7 @@ inline void QList::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 void QList::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()) {