summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.h
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-06-04 22:04:13 +0200
committerLars Knoll <lars.knoll@qt.io>2019-12-07 14:18:12 +0100
commit8fb45ae5b8b8ad276aeb9bc9e40f351f47523087 (patch)
treed6c3c40b59b9650f5ea6815afa06bac3cec78897 /src/corelib/tools/qarraydata.h
parent64db4861bfcacc8849e8452b73d5c940d97aefd0 (diff)
Introduce QArrayData::allocatedCapacity() and use it instead of d->alloc
In almost all cases, use d->allocatedCapacity() or d->constAllocatedCapacity() instead of d->alloc, since they do the same thing (right now). In the future, the functions will be changed. There is a separate const version because most const code should not need to know the allocation size -- only mutating code should need to know that There are a few cases where d->alloc was replaced with a better alternative, like d->size. The one case that remains in the code will be replaced by a different test when it's available. Change-Id: I48135469db4caf150f82df93fff42d2309b23719 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r--src/corelib/tools/qarraydata.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h
index 9a3b53338c..feee557131 100644
--- a/src/corelib/tools/qarraydata.h
+++ b/src/corelib/tools/qarraydata.h
@@ -55,6 +55,16 @@ struct Q_CORE_EXPORT QArrayData
qptrdiff offset; // in bytes from beginning of header
+ inline size_t allocatedCapacity()
+ {
+ return alloc;
+ }
+
+ inline size_t constAllocatedCapacity() const
+ {
+ return alloc;
+ }
+
void *data()
{
Q_ASSERT(size == 0
@@ -90,8 +100,8 @@ struct Q_CORE_EXPORT QArrayData
size_t detachCapacity(size_t newSize) const
{
- if (flags & CapacityReserved && newSize < alloc)
- return alloc;
+ if (flags & CapacityReserved && newSize < constAllocatedCapacity())
+ return constAllocatedCapacity();
return newSize;
}