Skip to content

Commit

Permalink
QArrayData: store the right flag type, not an int
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dangelog committed May 16, 2021
1 parent 8e82c30 commit 5ea5005
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/corelib/tools/qarraydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/tools/qarraydata.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct QArrayData
Q_DECLARE_FLAGS(ArrayOptions, ArrayOption)

QBasicAtomicInt ref_;
uint flags;
ArrayOptions flags;
qsizetype alloc;

qsizetype allocatedCapacity() noexcept
Expand Down
2 changes: 1 addition & 1 deletion src/corelib/tools/qarraydatapointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ struct QArrayDataPointer
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; }

Expand Down
2 changes: 1 addition & 1 deletion tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 5ea5005

Please sign in to comment.