summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2012-06-11 21:26:23 +0200
committerLars Knoll <lars.knoll@qt.io>2019-12-08 10:29:17 +0100
commit812a611dc05e5facd036856625ccb9274fdcb117 (patch)
tree06151f35165e3b2ae614d21be65e4555e19f45e7 /src/corelib/tools/qarraydata.cpp
parent62c673ccc6f81cee09a25f5acceec2768cea4672 (diff)
Stop using the reference counter to store data state
Instead of using the reference count to store whether the data is sharable and whether the header is immutable, move the settings to the flags member. This allows us to save one comparison per deref() or needsDetach(). It also allows for the possibility of mutable data pointed to by a static header. Change-Id: Ie678a2ff2bb9bce73497cb6138b431c465b0f3bb Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.cpp')
-rw-r--r--src/corelib/tools/qarraydata.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index fdd441c7de..aa7fac15ef 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -153,11 +153,11 @@ QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")
const QArrayData QArrayData::shared_null[2] = {
- { Q_REFCOUNT_INITIALIZE_STATIC, QArrayData::StaticDataFlags, 0, 0, sizeof(QArrayData) }, // shared null
+ { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0, 0, sizeof(QArrayData) }, // shared null
/* zero initialized terminator */};
static const QArrayData emptyNotNullShared[2] = {
- { Q_REFCOUNT_INITIALIZE_STATIC, QArrayData::StaticDataFlags, 0, 0, sizeof(QArrayData) }, // shared empty
+ { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0, 0, sizeof(QArrayData) }, // shared empty
/* zero initialized terminator */};
QT_WARNING_POP
@@ -183,7 +183,7 @@ static QArrayData *allocateData(size_t allocSize, uint options)
{
QArrayData *header = static_cast<QArrayData *>(::malloc(allocSize));
if (header) {
- header->ref_.atomic.storeRelaxed(1);
+ header->ref_.storeRelaxed(1);
header->flags = options;
header->size = 0;
}
@@ -222,7 +222,8 @@ QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
return nullptr;
size_t allocSize = calculateBlockSize(capacity, objectSize, headerSize, options);
- options |= AllocatedDataType | Mutable;
+ options |= AllocatedDataType | MutableData;
+ options &= ~ImmutableHeader;
QArrayData *header = allocateData(allocSize, options);
if (header) {
quintptr data = (quintptr(header) + sizeof(QArrayData) + alignment - 1)
@@ -249,10 +250,10 @@ QArrayData *QArrayData::reallocateUnaligned(QArrayData *data, size_t objectSize,
Q_ASSERT(data->isMutable());
Q_ASSERT(!data->isShared());
- options |= ArrayOption(AllocatedDataType);
size_t headerSize = sizeof(QArrayData);
size_t allocSize = calculateBlockSize(capacity, objectSize, headerSize, options);
- options |= AllocatedDataType | Mutable;
+ options |= AllocatedDataType | MutableData;
+ options &= ~ImmutableHeader;
QArrayData *header = reallocateData(data, allocSize, options);
if (header)
header->alloc = capacity;