summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2020-09-02 11:39:13 +0200
committerAndrei Golubev <andrei.golubev@qt.io>2020-09-02 23:10:25 +0200
commit27fed69d0a5842a718e9afe1b82851e2803fc084 (patch)
treee4d83f50052710f3f059a7fe434e5aaaf9a8d79b
parentb98b7de0da395be33e2d1646ac62075422ce4343 (diff)
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>
-rw-r--r--src/corelib/text/qstring.h2
-rw-r--r--src/corelib/tools/qlist.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/src/corelib/text/qstring.h b/src/corelib/text/qstring.h
index 7daf86a366..d86d659e75 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 bd593bae55..e94c108f0c 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -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()) {