diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/text/qstring.h | 2 | ||||
-rw-r--r-- | 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 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()) { |