9#include <QtCore/qpair.h>
10#include <QtCore/qatomic.h>
11#include <QtCore/qflags.h>
12#include <QtCore/qcontainerfwd.h>
18# define Q_DECL_MALLOCLIKE [[nodiscard, gnu::malloc]]
20# define Q_DECL_MALLOCLIKE [[nodiscard]] __declspec(allocator) __declspec(restrict)
22# define Q_DECL_MALLOCLIKE [[nodiscard]]
25template <
class T>
struct QTypedArrayData;
88 return ref_.loadRelaxed() != 1;
96 return ref_.loadRelaxed() > 1;
101 if (flags & CapacityReserved && newSize < constAllocatedCapacity())
102 return constAllocatedCapacity();
119 qsizetype alignment)
noexcept;
122Q_DECLARE_OPERATORS_FOR_FLAGS(
QArrayData::ArrayOptions)
126#if defined(Q_PROCESSOR_X86_32) && defined(Q_CC_GNU)
141struct QTypedArrayData
149 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
153 if constexpr (
sizeof(T) == 1) {
155 result = allocate1(&d, capacity, option);
156 }
else if constexpr (
sizeof(T) == 2) {
158 result = allocate2(&d, capacity, option);
160 result = QArrayData::allocate(&d,
sizeof(T),
alignof(
AlignmentDummy), capacity, option);
164 result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy));
166 return {
static_cast<QTypedArrayData *>(d),
static_cast<T *>(result)};
172 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
173 std::pair<QArrayData *,
void *> pair =
174 QArrayData::reallocateUnaligned(data, dataPointer,
sizeof(T), capacity, option);
175 return {
static_cast<QTypedArrayData *>(pair.first),
static_cast<T *>(pair.second)};
180 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
187 Q_ASSERT(alignment >= qsizetype(
alignof(
QArrayData)) && !(alignment & (alignment - 1)));
188 void *start =
reinterpret_cast<
void *>((quintptr(data) +
sizeof(
QArrayData) + alignment - 1)
189 & ~quintptr(alignment - 1));
190 return static_cast<T *>(start);
196 return (QtPrivate::MaxAllocSize -
sizeof(QtPrivate::AlignedQArrayData) - 1) /
sizeof(T);
242#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
QTypedArrayData< T > * header
QtPrivate::AlignedQArrayData header
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
static QTypedArrayAllocationResult< T > allocate(qsizetype capacity, AllocationOption option=QArrayData::KeepSize)
static QTypedArrayAllocationResult< T > reallocateUnaligned(QTypedArrayData *data, T *dataPointer, qsizetype capacity, AllocationOption option)