QT_BEGIN_NAMESPACE
const QArrayData QArrayData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
-const QArrayData QArrayData::shared_empty = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
-const QArrayData QArrayData::unsharable_empty = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
+
+static const QArrayData qt_array_empty = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, 0 };
+static const QArrayData qt_array_unsharable_empty = { { Q_BASIC_ATOMIC_INITIALIZER(0) }, 0, 0, 0, 0 };
QArrayData *QArrayData::allocate(size_t objectSize, size_t alignment,
size_t capacity, bool reserve, bool sharable)
// Don't allocate empty headers
if (!capacity)
return sharable
- ? const_cast<QArrayData *>(&shared_empty)
- : const_cast<QArrayData *>(&unsharable_empty);
+ ? const_cast<QArrayData *>(&qt_array_empty)
+ : const_cast<QArrayData *>(&qt_array_unsharable_empty);
// Allocate extra (alignment - Q_ALIGNOF(QArrayData)) padding bytes so we
// can properly align the data array. This assumes malloc is able to
&& !(alignment & (alignment - 1)));
Q_UNUSED(objectSize) Q_UNUSED(alignment)
- if (data == &unsharable_empty)
+ if (data == &qt_array_unsharable_empty)
return;
qFree(data);
size_t alignment);
static const QArrayData shared_null;
- static const QArrayData shared_empty;
- static const QArrayData unsharable_empty;
};
template <class T>
return static_cast<QTypedArrayData *>(
const_cast<QArrayData *>(&QArrayData::shared_null));
}
-
- static QTypedArrayData *sharedEmpty()
- {
- return static_cast<QTypedArrayData *>(
- const_cast<QArrayData *>(&QArrayData::shared_empty));
- }
-
- static QTypedArrayData *unsharableEmpty()
- {
- return static_cast<QTypedArrayData *>(
- const_cast<QArrayData *>(&QArrayData::unsharable_empty));
- }
};
template <class T, size_t N>
void setSharable(bool sharable)
{
if (d->alloc == 0 && d->size == 0) {
- Q_ASSERT(Data::sharedNull() == d
- || Data::sharedEmpty() == d
- || Data::unsharableEmpty() == d);
- d = sharable
- ? Data::sharedEmpty()
- : Data::unsharableEmpty();
+ d = Data::allocate(0, false, sharable);
return;
}
void clear()
{
QArrayDataPointer tmp(d);
- d = Data::sharedEmpty();
+ d = Data::allocate(0);
}
bool detach()
void tst_QArrayData::sharedNullEmpty()
{
QArrayData *null = const_cast<QArrayData *>(&QArrayData::shared_null);
- QArrayData *empty = const_cast<QArrayData *>(&QArrayData::shared_empty);
+ QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0, false, true);
QVERIFY(null->ref.isStatic());
QVERIFY(null->ref.isSharable());
{ "void *", sizeof(void *), Q_ALIGNOF(void *) }
};
+ QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, false, true);
+ QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, false, false);
+
+ QVERIFY(shared_empty);
+ QVERIFY(unsharable_empty);
+
struct {
char const *description;
bool isCapacityReserved;
bool isSharable;
const QArrayData *commonEmpty;
} options[] = {
- { "Default", false, true, &QArrayData::shared_empty },
- { "Reserved", true, true, &QArrayData::shared_empty },
- { "Reserved | Unsharable", true, false, &QArrayData::unsharable_empty },
- { "Unsharable", false, false, &QArrayData::unsharable_empty },
+ { "Default", false, true, shared_empty },
+ { "Reserved", true, true, shared_empty },
+ { "Reserved | Unsharable", true, false, unsharable_empty },
+ { "Unsharable", false, false, unsharable_empty },
};
for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i)
{
QTypedArrayData<int> *null = QTypedArrayData<int>::sharedNull();
- QTypedArrayData<int> *empty = QTypedArrayData<int>::sharedEmpty();
+ QTypedArrayData<int> *empty = QTypedArrayData<int>::allocate(0);
QVERIFY(null != empty);