summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.h
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/corelib/tools/qarraydata.h
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/corelib/tools/qarraydata.h')
-rw-r--r--src/corelib/tools/qarraydata.h7
1 files changed, 7 insertions, 0 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;