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:
parent
8e82c30680
commit
5ea50054a1
@ -178,7 +178,7 @@ static QArrayData *allocateData(qsizetype allocSize)
|
|||||||
QArrayData *header = static_cast<QArrayData *>(::malloc(size_t(allocSize)));
|
QArrayData *header = static_cast<QArrayData *>(::malloc(size_t(allocSize)));
|
||||||
if (header) {
|
if (header) {
|
||||||
header->ref_.storeRelaxed(1);
|
header->ref_.storeRelaxed(1);
|
||||||
header->flags = 0;
|
header->flags = {};
|
||||||
header->alloc = 0;
|
header->alloc = 0;
|
||||||
}
|
}
|
||||||
return header;
|
return header;
|
||||||
|
@ -68,7 +68,7 @@ struct QArrayData
|
|||||||
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)
|
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)
|
||||||
|
|
||||||
QBasicAtomicInt ref_;
|
QBasicAtomicInt ref_;
|
||||||
uint flags;
|
ArrayOptions flags;
|
||||||
qsizetype alloc;
|
qsizetype alloc;
|
||||||
|
|
||||||
qsizetype allocatedCapacity() noexcept
|
qsizetype allocatedCapacity() noexcept
|
||||||
|
@ -330,7 +330,7 @@ public:
|
|||||||
bool isSharedWith(const QArrayDataPointer &other) const noexcept { return d && d == other.d; }
|
bool isSharedWith(const QArrayDataPointer &other) const noexcept { return d && d == other.d; }
|
||||||
bool needsDetach() const noexcept { return !d || d->needsDetach(); }
|
bool needsDetach() const noexcept { return !d || d->needsDetach(); }
|
||||||
qsizetype detachCapacity(qsizetype newSize) const noexcept { return d ? d->detachCapacity(newSize) : newSize; }
|
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 setFlag(typename Data::ArrayOptions f) noexcept { Q_ASSERT(d); d->flags |= f; }
|
||||||
void clearFlag(typename Data::ArrayOptions f) noexcept { if (d) d->flags &= ~f; }
|
void clearFlag(typename Data::ArrayOptions f) noexcept { if (d) d->flags &= ~f; }
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void tst_QArrayData::referenceCounting()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
// Reference counting initialized to 1 (owned)
|
// 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);
|
QCOMPARE(array.ref_.loadRelaxed(), 1);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user