8#include <QtCore/qpair.h>
9#include <QtCore/qatomic.h>
10#include <QtCore/qflags.h>
11#include <QtCore/qcontainerfwd.h>
17# define Q_DECL_MALLOCLIKE [[nodiscard, gnu::malloc]]
19# define Q_DECL_MALLOCLIKE __declspec(allocator) __declspec(restrict) [[nodiscard]]
21# define Q_DECL_MALLOCLIKE [[nodiscard]]
24template <
class T>
struct QTypedArrayData;
73 return ref_.loadRelaxed() != 1;
81 return ref_.loadRelaxed() > 1;
86 if (flags & CapacityReserved && newSize < constAllocatedCapacity())
87 return constAllocatedCapacity();
104 qsizetype alignment)
noexcept;
107Q_DECLARE_OPERATORS_FOR_FLAGS(
QArrayData::ArrayOptions)
111#if defined(Q_PROCESSOR_X86_32) && defined(Q_CC_GNU)
126struct QTypedArrayData
133 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
136 if constexpr (
sizeof(T) == 1) {
138 result = allocate1(&d, capacity, option);
139 }
else if constexpr (
sizeof(T) == 2) {
141 result = allocate2(&d, capacity, option);
143 result = QArrayData::allocate(&d,
sizeof(T),
alignof(
AlignmentDummy), capacity, option);
147 result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy));
149 return {
static_cast<QTypedArrayData *>(d),
static_cast<T *>(result)};
155 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
156 std::pair<QArrayData *,
void *> pair =
157 QArrayData::reallocateUnaligned(data, dataPointer,
sizeof(T), capacity, option);
158 return {
static_cast<QTypedArrayData *>(pair.first),
static_cast<T *>(pair.second)};
163 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
170 Q_ASSERT(alignment >= qsizetype(
alignof(
QArrayData)) && !(alignment & (alignment - 1)));
171 void *start =
reinterpret_cast<
void *>(
172 (quintptr(data) +
sizeof(
QArrayData) + alignment - 1) & ~(alignment - 1));
173 return static_cast<T *>(start);
179 return (QtPrivate::MaxAllocSize -
sizeof(QtPrivate::AlignedQArrayData) - 1) /
sizeof(T);
225#undef Q_DECL_MALLOCLIKE
constexpr size_t MaxPrimitiveAlignment
#define Q_DECL_MALLOCLIKE
#define __has_cpp_attribute(x)
qsizetype detachCapacity(qsizetype newSize) const noexcept
@ CapacityReserved
the capacity was reserved by the user, try to keep it
bool deref() noexcept
Returns false if deallocation is necessary.
bool isShared() const noexcept
qsizetype constAllocatedCapacity() const noexcept
static Q_DECL_MALLOCLIKE Q_CORE_EXPORT void * allocate(QArrayData **pdata, qsizetype objectSize, qsizetype alignment, qsizetype capacity, AllocationOption option=QArrayData::KeepSize) noexcept
static Q_CORE_EXPORT void deallocate(QArrayData *data, qsizetype objectSize, qsizetype alignment) noexcept
bool needsDetach() noexcept
static Q_DECL_MALLOCLIKE Q_CORE_EXPORT void * allocate2(QArrayData **pdata, qsizetype capacity, AllocationOption option=QArrayData::KeepSize) noexcept
qsizetype allocatedCapacity() noexcept
bool ref() noexcept
Returns true if sharing took place.
static Q_DECL_MALLOCLIKE Q_CORE_EXPORT void * allocate1(QArrayData **pdata, qsizetype capacity, AllocationOption option=QArrayData::KeepSize) noexcept
QtPrivate::AlignedQArrayData header
static std::pair< QTypedArrayData *, T * > reallocateUnaligned(QTypedArrayData *data, T *dataPointer, qsizetype capacity, AllocationOption option)
static std::pair< QTypedArrayData *, T * > allocate(qsizetype capacity, AllocationOption option=QArrayData::KeepSize)
static constexpr qsizetype maxSize() noexcept
static constexpr qsizetype max_size() noexcept
static void deallocate(QArrayData *data) noexcept
static T * dataStart(QArrayData *data, qsizetype alignment) noexcept