QArrayData: store the right flag type, not an int

There's no reason to be storing `int` in the array data header and
then using it as a QFlags. Just store the QFlags.

Change-Id: I78f489550d74d15a560dacf338110d80a7ddfdd2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Giuseppe D'Angelo 2021-05-02 02:17:14 +02:00
parent 8e82c30680
commit 5ea50054a1
4 changed files with 4 additions and 4 deletions

View File

@ -178,7 +178,7 @@ static QArrayData *allocateData(qsizetype allocSize)
QArrayData *header = static_cast<QArrayData *>(::malloc(size_t(allocSize)));
if (header) {
header->ref_.storeRelaxed(1);
header->flags = 0;
header->flags = {};
header->alloc = 0;
}
return header;

View File

@ -68,7 +68,7 @@ struct QArrayData
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)
QBasicAtomicInt ref_;
uint flags;
ArrayOptions flags;
qsizetype alloc;
qsizetype allocatedCapacity() noexcept

View File

@ -330,7 +330,7 @@ public:
bool isSharedWith(const QArrayDataPointer &other) const noexcept { return d && d == other.d; }
bool needsDetach() const noexcept { return !d || d->needsDetach(); }
qsizetype detachCapacity(qsizetype newSize) const noexcept { return d ? d->detachCapacity(newSize) : newSize; }
const typename Data::ArrayOptions flags() const noexcept { return d ? typename Data::ArrayOption(d->flags) : Data::ArrayOptionDefault; }
const typename Data::ArrayOptions flags() const noexcept { return d ? d->flags : Data::ArrayOptionDefault; }
void setFlag(typename Data::ArrayOptions f) noexcept { Q_ASSERT(d); d->flags |= f; }
void clearFlag(typename Data::ArrayOptions f) noexcept { if (d) d->flags &= ~f; }

View File

@ -97,7 +97,7 @@ void tst_QArrayData::referenceCounting()
{
{
// Reference counting initialized to 1 (owned)
QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), 0, 0 };
QArrayData array = { Q_BASIC_ATOMIC_INITIALIZER(1), {}, 0 };
QCOMPARE(array.ref_.loadRelaxed(), 1);