diff options
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 7 | ||||
-rw-r--r-- | src/corelib/tools/qarraydatapointer.h | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index ae4cbc3081..78fbc9cf32 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -91,6 +91,13 @@ struct Q_CORE_EXPORT QArrayData Q_DECLARE_FLAGS(AllocationOptions, AllocationOption) + size_t detachCapacity(size_t newSize) const + { + if (capacityReserved && newSize < alloc) + return alloc; + return newSize; + } + AllocationOptions detachFlags() const { AllocationOptions result; diff --git a/src/corelib/tools/qarraydatapointer.h b/src/corelib/tools/qarraydatapointer.h index f5ad53aa54..4eb90ac35e 100644 --- a/src/corelib/tools/qarraydatapointer.h +++ b/src/corelib/tools/qarraydatapointer.h @@ -171,7 +171,7 @@ public: private: Data *clone(QArrayData::AllocationOptions options) const Q_REQUIRED_RESULT { - QArrayDataPointer copy(Data::allocate(d->alloc ? d->alloc : d->size, + QArrayDataPointer copy(Data::allocate(d->detachCapacity(d->size), options)); if (d->size) copy->copyAppend(d->begin(), d->end()); |