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 [[nodiscard]]
22template <
class T>
struct QTypedArrayData;
71 return ref_.loadRelaxed() != 1;
79 return ref_.loadRelaxed() > 1;
84 if (flags & CapacityReserved && newSize < constAllocatedCapacity())
85 return constAllocatedCapacity();
102 qsizetype alignment)
noexcept;
105Q_DECLARE_OPERATORS_FOR_FLAGS(
QArrayData::ArrayOptions)
109#if defined(Q_PROCESSOR_X86_32) && defined(Q_CC_GNU)
124struct QTypedArrayData
131 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
134 if constexpr (
sizeof(T) == 1) {
136 result = allocate1(&d, capacity, option);
137 }
else if constexpr (
sizeof(T) == 2) {
139 result = allocate2(&d, capacity, option);
141 result = QArrayData::allocate(&d,
sizeof(T),
alignof(
AlignmentDummy), capacity, option);
145 result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy));
147 return {
static_cast<QTypedArrayData *>(d),
static_cast<T *>(result)};
153 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
154 std::pair<QArrayData *,
void *> pair =
155 QArrayData::reallocateUnaligned(data, dataPointer,
sizeof(T), capacity, option);
156 return {
static_cast<QTypedArrayData *>(pair.first),
static_cast<T *>(pair.second)};
161 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
168 Q_ASSERT(alignment >= qsizetype(
alignof(
QArrayData)) && !(alignment & (alignment - 1)));
169 void *start =
reinterpret_cast<
void *>(
170 (quintptr(data) +
sizeof(
QArrayData) + alignment - 1) & ~(alignment - 1));
171 return static_cast<T *>(start);
177 return (QtPrivate::MaxAllocSize -
sizeof(QtPrivate::AlignedQArrayData) - 1) /
sizeof(T);
223#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