Get rid of unused flags in QArrayData

Change-Id: I3ea754b44fb33e33baba0781d9ae15b7f3b3d8eb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Lars Knoll 2019-12-02 16:06:48 +01:00
parent a8d5f38537
commit f8a53388a7
4 changed files with 13 additions and 45 deletions

View File

@ -153,11 +153,11 @@ QT_WARNING_PUSH
QT_WARNING_DISABLE_GCC("-Wmissing-field-initializers")
const QArrayData QArrayData::shared_null[2] = {
{ Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }, // shared null
{ Q_BASIC_ATOMIC_INITIALIZER(-1), 0, 0 }, // shared null
/* zero initialized terminator */};
static const QArrayData emptyNotNullShared[2] = {
{ Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 }, // shared empty
{ Q_BASIC_ATOMIC_INITIALIZER(-1), 0, 0 }, // shared empty
/* zero initialized terminator */};
QT_WARNING_POP
@ -217,8 +217,6 @@ void *QArrayData::allocate(QArrayData **dptr, size_t objectSize, size_t alignmen
return nullptr;
size_t allocSize = calculateBlockSize(capacity, objectSize, headerSize, options);
options |= AllocatedDataType | MutableData;
options &= ~ImmutableHeader;
QArrayData *header = allocateData(allocSize, options);
quintptr data = 0;
if (header) {
@ -241,7 +239,6 @@ QArrayData::reallocateUnaligned(QArrayData *data, void *dataPointer,
size_t headerSize = sizeof(QArrayData);
size_t allocSize = calculateBlockSize(capacity, objectSize, headerSize, options);
qptrdiff offset = dataPointer ? reinterpret_cast<char *>(dataPointer) - reinterpret_cast<char *>(data) : headerSize;
options |= AllocatedDataType | MutableData;
QArrayData *header = static_cast<QArrayData *>(::realloc(data, size_t(allocSize)));
if (header) {
header->flags = options;
@ -260,8 +257,6 @@ void QArrayData::deallocate(QArrayData *data, size_t objectSize,
Q_UNUSED(objectSize);
Q_UNUSED(alignment);
Q_ASSERT_X(data == nullptr || !data->isStatic(), "QArrayData::deallocate",
"Static data cannot be deleted");
::free(data);
}

View File

@ -52,22 +52,11 @@ template <class T> struct QTypedArrayData;
struct Q_CORE_EXPORT QArrayData
{
enum ArrayOption {
RawDataType = 0x0001, //!< this class is really a QArrayData
AllocatedDataType = 0x0002, //!< this class is really a QArrayAllocatedData
DataTypeBits = 0x000f,
CapacityReserved = 0x0010, //!< the capacity was reserved by the user, try to keep it
GrowsForward = 0x0020, //!< allocate with eyes towards growing through append()
GrowsBackwards = 0x0040, //!< allocate with eyes towards growing through prepend()
MutableData = 0x0080, //!< the data can be changed; doesn't say anything about the header
ImmutableHeader = 0x0100, //!< the header is static, it can't be changed
/// this option is used by the Q_ARRAY_LITERAL and similar macros
StaticDataFlags = RawDataType | ImmutableHeader,
/// this option is used by the allocate() function
DefaultAllocationFlags = MutableData,
/// this option is used by the prepareRawData() function
DefaultRawFlags = 0
DefaultAllocationFlags = 0,
CapacityReserved = 0x1, //!< the capacity was reserved by the user, try to keep it
GrowsForward = 0x2, //!< allocate with eyes towards growing through append()
GrowsBackwards = 0x4 //!< allocate with eyes towards growing through prepend()
};
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)
@ -106,12 +95,12 @@ struct Q_CORE_EXPORT QArrayData
// follow COW principles.
bool isMutable() const
{
return flags & MutableData;
return ref_.loadRelaxed() != -1;
}
bool isStatic() const
{
return flags & ImmutableHeader;
return !isMutable();
}
bool isShared() const

View File

@ -148,14 +148,13 @@ private slots:
void stdString();
};
static const QArrayData staticDataFlags = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 };
static const QByteArray::DataPointer staticStandard = {
static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)),
nullptr,
const_cast<char *>("data"),
4
};
static const QByteArray::DataPointer staticNotNullTerminated = {
static_cast<QTypedArrayData<char> *>(const_cast<QArrayData *>(&staticDataFlags)),
nullptr,
const_cast<char *>("dataBAD"),
4
};
@ -168,8 +167,8 @@ QByteArray verifyZeroTermination(const QByteArray &ba)
QByteArray::DataPointer baDataPtr = const_cast<QByteArray &>(ba).data_ptr();
// Skip if isStatic() or fromRawData(), as those offer no guarantees
if (baDataPtr->isStatic() || baDataPtr->flags() & QArrayData::RawDataType)
// Skip if isStatic() as those offer no guarantees
if (baDataPtr->isStatic())
return ba;
int baSize = ba.size();

View File

@ -83,7 +83,7 @@ void tst_QArrayData::referenceCounting()
{
{
// Reference counting initialized to 1 (owned)
QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), QArrayData::DefaultRawFlags, 0 };
QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 };
QCOMPARE(array.ref_.loadRelaxed(), 1);
@ -106,21 +106,6 @@ void tst_QArrayData::referenceCounting()
// Now would be a good time to free/release allocated data
}
{
// Reference counting initialized to -1 (static read-only data)
QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(-1), QArrayData::StaticDataFlags, 0 };
QCOMPARE(array.ref_.loadRelaxed(), -1);
QVERIFY(array.isStatic());
QVERIFY(array.ref());
QCOMPARE(array.ref_.loadRelaxed(), -1);
QVERIFY(array.deref());
QCOMPARE(array.ref_.loadRelaxed(), -1);
}
}
void tst_QArrayData::sharedNullEmpty()