diff options
Diffstat (limited to 'src/corelib/tools/qarraydata.h')
-rw-r--r-- | src/corelib/tools/qarraydata.h | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/corelib/tools/qarraydata.h b/src/corelib/tools/qarraydata.h index 2486bebafa..8eb543ee51 100644 --- a/src/corelib/tools/qarraydata.h +++ b/src/corelib/tools/qarraydata.h @@ -73,14 +73,43 @@ struct Q_CORE_EXPORT QArrayData return reinterpret_cast<const char *>(this) + offset; } + enum AllocateOption { + CapacityReserved = 0x1, + Unsharable = 0x2, + + Default = 0 + }; + + Q_DECLARE_FLAGS(AllocateOptions, AllocateOption) + + AllocateOptions detachFlags() const + { + AllocateOptions result; + if (!ref.isSharable()) + result |= Unsharable; + if (capacityReserved) + result |= CapacityReserved; + return result; + } + + AllocateOptions cloneFlags() const + { + AllocateOptions result; + if (capacityReserved) + result |= CapacityReserved; + return result; + } + static QArrayData *allocate(size_t objectSize, size_t alignment, - size_t capacity, bool reserve, bool sharable) Q_REQUIRED_RESULT; + size_t capacity, AllocateOptions options = Default) Q_REQUIRED_RESULT; static void deallocate(QArrayData *data, size_t objectSize, size_t alignment); static const QArrayData shared_null; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QArrayData::AllocateOptions) + template <class T> struct QTypedArrayData : QArrayData @@ -98,11 +127,11 @@ struct QTypedArrayData class AlignmentDummy { QArrayData header; T data; }; - static QTypedArrayData *allocate(size_t capacity, bool reserve = false, - bool sharable = true) Q_REQUIRED_RESULT + static QTypedArrayData *allocate(size_t capacity, + AllocateOptions options = Default) Q_REQUIRED_RESULT { return static_cast<QTypedArrayData *>(QArrayData::allocate(sizeof(T), - Q_ALIGNOF(AlignmentDummy), capacity, reserve, sharable)); + Q_ALIGNOF(AlignmentDummy), capacity, options)); } static void deallocate(QArrayData *data) |