QArrayData: change calculateBlockSize() to not have an in/out parameter
Won't make a difference in codegen, but it's the right thing to do. Pick-to: 6.6 Change-Id: Ifa1111900d6945ea8e05fffd177dc8d200c2368f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
parent
763592b238
commit
167d28e77a
@ -123,17 +123,16 @@ static inline qsizetype reserveExtraBytes(qsizetype allocSize)
|
|||||||
return allocSize;
|
return allocSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline qsizetype calculateBlockSize(qsizetype &capacity, qsizetype objectSize, qsizetype headerSize, QArrayData::AllocationOption option)
|
static inline CalculateGrowingBlockSizeResult
|
||||||
|
calculateBlockSize(qsizetype capacity, qsizetype objectSize, qsizetype headerSize, QArrayData::AllocationOption option)
|
||||||
{
|
{
|
||||||
// Calculate the byte size
|
// Calculate the byte size
|
||||||
// allocSize = objectSize * capacity + headerSize, but checked for overflow
|
// allocSize = objectSize * capacity + headerSize, but checked for overflow
|
||||||
// plus padded to grow in size
|
// plus padded to grow in size
|
||||||
if (option == QArrayData::Grow) {
|
if (option == QArrayData::Grow) {
|
||||||
auto r = qCalculateGrowingBlockSize(capacity, objectSize, headerSize);
|
return qCalculateGrowingBlockSize(capacity, objectSize, headerSize);
|
||||||
capacity = r.elementCount;
|
|
||||||
return r.size;
|
|
||||||
} else {
|
} else {
|
||||||
return qCalculateBlockSize(capacity, objectSize, headerSize);
|
return { qCalculateBlockSize(capacity, objectSize, headerSize), capacity };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,8 +180,9 @@ void *QArrayData::allocate(QArrayData **dptr, qsizetype objectSize, qsizetype al
|
|||||||
}
|
}
|
||||||
Q_ASSERT(headerSize > 0);
|
Q_ASSERT(headerSize > 0);
|
||||||
|
|
||||||
qsizetype allocSize = calculateBlockSize(capacity, objectSize, headerSize, option);
|
auto blockSize = calculateBlockSize(capacity, objectSize, headerSize, option);
|
||||||
allocSize = reserveExtraBytes(allocSize);
|
capacity = blockSize.elementCount;
|
||||||
|
qsizetype allocSize = reserveExtraBytes(blockSize.size);
|
||||||
if (Q_UNLIKELY(allocSize < 0)) { // handle overflow. cannot allocate reliably
|
if (Q_UNLIKELY(allocSize < 0)) { // handle overflow. cannot allocate reliably
|
||||||
*dptr = nullptr;
|
*dptr = nullptr;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -207,7 +207,9 @@ QArrayData::reallocateUnaligned(QArrayData *data, void *dataPointer,
|
|||||||
Q_ASSERT(!data || !data->isShared());
|
Q_ASSERT(!data || !data->isShared());
|
||||||
|
|
||||||
const qsizetype headerSize = sizeof(AlignedQArrayData);
|
const qsizetype headerSize = sizeof(AlignedQArrayData);
|
||||||
qsizetype allocSize = calculateBlockSize(capacity, objectSize, headerSize, option);
|
auto r = calculateBlockSize(capacity, objectSize, headerSize, option);
|
||||||
|
qsizetype allocSize = r.size;
|
||||||
|
capacity = r.elementCount;
|
||||||
if (Q_UNLIKELY(allocSize < 0))
|
if (Q_UNLIKELY(allocSize < 0))
|
||||||
return qMakePair<QArrayData *, void *>(nullptr, nullptr);
|
return qMakePair<QArrayData *, void *>(nullptr, nullptr);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user