summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-03-05 17:43:34 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-02 16:34:21 +0200
commit8c413f3eff2de761ae038294195831de753b9252 (patch)
tree124d46015c194aa91fd3df68f694761f6819cf02 /src
parent646dc6c5daeefa99c9af070802c39bc66dc4f1f0 (diff)
Introduce QArrayData::detachCapacity
This follows QArrayData::detachFlags's lead. Given the (known) size for a detached container, the function helps determine capacity, ensuring the capacityReserved flag is respected. This further helps aggregating behaviour on detach in QArrayData itself. SimpleVector was previously using qMax(capacity(), newSize), but there's no reason to pin the previous capacity value if reserve() wasn't requested. It now uses detachCapacity(). Change-Id: Ide2d99ea7ecd2cd98ae4c1aa397b4475d09c8485 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qarraydata.h7
-rw-r--r--src/corelib/tools/qarraydatapointer.h2
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());