diff options
| author | Thiago Macieira <thiago.macieira@intel.com> | 2025-07-09 13:10:15 -0700 |
|---|---|---|
| committer | Thiago Macieira <thiago.macieira@intel.com> | 2025-08-05 13:52:35 -0700 |
| commit | 2ebd327712b23b1ec136bc613ef60076cbc1b803 (patch) | |
| tree | 498ed51614ba7730a31bce86b4e02ea9500a0136 /src/corelib/tools/qarraydata.cpp | |
| parent | e551a80b0d9ef33495f50bfd91ff7b921348956b (diff) | |
QArrayData: remove AllocationResult and go back to output parameter
The public API must have a single pointer return value because of
limitations of GCC's __attribute__((malloc)), meaning we have no option
but to have an output parameter for that too. Therefore, this simplifies
the internals.
Pick-to: 6.10
Change-Id: I0c12029a2f29fbbfd610fffd8d4931eca962b2e3
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib/tools/qarraydata.cpp')
| -rw-r--r-- | src/corelib/tools/qarraydata.cpp | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp index 54bd971cb36..1c0371e463e 100644 --- a/src/corelib/tools/qarraydata.cpp +++ b/src/corelib/tools/qarraydata.cpp @@ -157,17 +157,11 @@ calculateBlockSize(qsizetype capacity, qsizetype objectSize, qsizetype headerSiz } } -namespace { -struct AllocationResult { - void *data; - QArrayData *header; -}; -} - -static inline AllocationResult -allocateHelper(qsizetype objectSize, qsizetype alignment, qsizetype capacity, +static inline void * +allocateHelper(QArrayData **dptr, qsizetype objectSize, qsizetype alignment, qsizetype capacity, QArrayData::AllocationOption option) noexcept { + *dptr = nullptr; if (capacity == 0) return {}; @@ -182,14 +176,13 @@ allocateHelper(qsizetype objectSize, qsizetype alignment, qsizetype capacity, void *data = nullptr; void *mem = ::malloc(size_t(allocSize)); - QArrayData *header = nullptr; if (Q_LIKELY(mem)) { - header = new (mem) QArrayData{1, {}, capacity}; + *dptr = new (mem) QArrayData{1, {}, capacity}; // find where offset should point to so that data() is aligned to alignment bytes - data = QTypedArrayData<void>::dataStart(header, alignment); + data = QTypedArrayData<void>::dataStart(*dptr, alignment); } - return { data, header }; + return data; } // Generic size and alignment allocation function @@ -201,9 +194,7 @@ void *QArrayData::allocate(QArrayData **dptr, qsizetype objectSize, qsizetype al Q_ASSERT(alignment >= qsizetype(alignof(QArrayData)) && !(alignment & (alignment - 1))); - auto r = allocateHelper(objectSize, alignment, capacity, option); - *dptr = r.header; - return r.data; + return allocateHelper(dptr, objectSize, alignment, capacity, option); } // Fixed size and alignment allocation functions @@ -211,18 +202,14 @@ void *QArrayData::allocate1(QArrayData **dptr, qsizetype capacity, AllocationOpt { Q_ASSERT(dptr); - auto r = allocateHelper(1, alignof(AlignedQArrayData), capacity, option); - *dptr = r.header; - return r.data; + return allocateHelper(dptr, 1, alignof(AlignedQArrayData), capacity, option); } void *QArrayData::allocate2(QArrayData **dptr, qsizetype capacity, AllocationOption option) noexcept { Q_ASSERT(dptr); - auto r = allocateHelper(2, alignof(AlignedQArrayData), capacity, option); - *dptr = r.header; - return r.data; + return allocateHelper(dptr, 2, alignof(AlignedQArrayData), capacity, option); } std::pair<QArrayData *, void *> |
