diff options
author | Lars Knoll <lars.knoll@qt.io> | 2020-10-30 14:21:34 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2020-11-04 11:21:46 +0100 |
commit | b76fbb48fba51df95d1776b8c1ff358789d78031 (patch) | |
tree | 1955e13a6498318d8d485805af1558d995924829 /src/corelib/tools/qarraydata.h | |
parent | 419eaa0679c3867d8d9a3da8845a3015e29800d7 (diff) |
Clean up out allocation handling
Get rid of the allocation options inside the flags
field of QArrayData, they are really a completely
separate thing.
Change-Id: I823750ab9e4ca85642a0bd0e471ee79c9cde43fb
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 76f2c33043..9ada91d04b 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -56,12 +56,14 @@ struct Q_CORE_EXPORT QArrayData KeepSize }; - enum ArrayOption { - /// this option is used by the allocate() function - 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() + enum AllocationPosition { + AllocateAtEnd, + AllocateAtBeginning + }; + + enum ArrayOption { + ArrayOptionDefault = 0, + CapacityReserved = 0x1 //!< the capacity was reserved by the user, try to keep it }; Q_DECLARE_FLAGS(ArrayOptions, ArrayOption) @@ -112,20 +114,12 @@ struct Q_CORE_EXPORT QArrayData return newSize; } - ArrayOptions detachFlags() const noexcept - { - ArrayOptions result = DefaultAllocationFlags; - if (flags & CapacityReserved) - result |= CapacityReserved; - return result; - } - [[nodiscard]] #if defined(Q_CC_GNU) __attribute__((__malloc__)) #endif static void *allocate(QArrayData **pdata, qsizetype objectSize, qsizetype alignment, - qsizetype capacity, ArrayOptions options = DefaultAllocationFlags) noexcept; + qsizetype capacity, AllocationOption option = QArrayData::KeepSize) noexcept; [[nodiscard]] static QPair<QArrayData *, void *> reallocateUnaligned(QArrayData *data, void *dataPointer, qsizetype objectSize, qsizetype newCapacity, AllocationOption option) noexcept; static void deallocate(QArrayData *data, qsizetype objectSize, @@ -213,12 +207,11 @@ struct QTypedArrayData struct AlignmentDummy { QArrayData header; T data; }; - [[nodiscard]] static QPair<QTypedArrayData *, T *> allocate(qsizetype capacity, - ArrayOptions options = DefaultAllocationFlags) + [[nodiscard]] static QPair<QTypedArrayData *, T *> allocate(qsizetype capacity, AllocationOption option = QArrayData::KeepSize) { static_assert(sizeof(QTypedArrayData) == sizeof(QArrayData)); QArrayData *d; - void *result = QArrayData::allocate(&d, sizeof(T), alignof(AlignmentDummy), capacity, options); + void *result = QArrayData::allocate(&d, sizeof(T), alignof(AlignmentDummy), capacity, option); #if (defined(Q_CC_GNU) && Q_CC_GNU >= 407) || QT_HAS_BUILTIN(__builtin_assume_aligned) result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy)); #endif |