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 __declspec(allocator) __declspec(restrict) [[nodiscard]]
22# define Q_DECL_MALLOCLIKE [[nodiscard]]
25template <
class T>
struct QTypedArrayData;
84 return ref_.loadRelaxed() != 1;
92 return ref_.loadRelaxed() > 1;
97 if (flags & CapacityReserved && newSize < constAllocatedCapacity())
98 return constAllocatedCapacity();
115 qsizetype alignment)
noexcept;
118Q_DECLARE_OPERATORS_FOR_FLAGS(
QArrayData::ArrayOptions)
122#if defined(Q_PROCESSOR_X86_32) && defined(Q_CC_GNU)
137struct QTypedArrayData
145 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
148 if constexpr (
sizeof(T) == 1) {
150 result = allocate1(&d, capacity, option);
151 }
else if constexpr (
sizeof(T) == 2) {
153 result = allocate2(&d, capacity, option);
155 result = QArrayData::allocate(&d,
sizeof(T),
alignof(
AlignmentDummy), capacity, option);
159 result = __builtin_assume_aligned(result, Q_ALIGNOF(AlignmentDummy));
161 return {
static_cast<QTypedArrayData *>(d),
static_cast<T *>(result)};
167 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
168 std::pair<QArrayData *,
void *> pair =
169 QArrayData::reallocateUnaligned(data, dataPointer,
sizeof(T), capacity, option);
170 return {
static_cast<QTypedArrayData *>(pair.first),
static_cast<T *>(pair.second)};
175 static_assert(
sizeof(QTypedArrayData) ==
sizeof(
QArrayData));
182 Q_ASSERT(alignment >= qsizetype(
alignof(
QArrayData)) && !(alignment & (alignment - 1)));
183 void *start =
reinterpret_cast<
void *>(
184 (quintptr(data) +
sizeof(
QArrayData) + alignment - 1) & ~(alignment - 1));
185 return static_cast<T *>(start);
191 return (QtPrivate::MaxAllocSize -
sizeof(QtPrivate::AlignedQArrayData) - 1) /
sizeof(T);
237#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)