summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qarraydata.cpp
diff options
context:
space:
mode:
authorAurélien Brooke <aurelien@bahiasoft.fr>2025-01-24 17:08:15 +0100
committerAurélien Brooke <aurelien@bahiasoft.fr>2025-01-30 10:38:51 +0100
commited7d59c0a266bf578c3a9203c0107ab2ed29f067 (patch)
tree691d32b154b681cc9b0df17bebd6e761f668b11e /src/corelib/tools/qarraydata.cpp
parent5229cba24fff0bb348c37332e2209579e368103a (diff)
QArrayData: inline the allocateData function
It is already inlined by the compiler so this is a effectively a no-op. The aim of this change is to make later work in this file cleaner and easier to review. Deduplicate the if check and alloc assignment, and remove the unnecessary qsizetype cast. Change-Id: I139f1132779ce4c583a5be689800940801142d36 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools/qarraydata.cpp')
-rw-r--r--src/corelib/tools/qarraydata.cpp19
1 files changed, 5 insertions, 14 deletions
diff --git a/src/corelib/tools/qarraydata.cpp b/src/corelib/tools/qarraydata.cpp
index 6aebd4306a5..5452fddaa89 100644
--- a/src/corelib/tools/qarraydata.cpp
+++ b/src/corelib/tools/qarraydata.cpp
@@ -134,17 +134,6 @@ calculateBlockSize(qsizetype capacity, qsizetype objectSize, qsizetype headerSiz
}
}
-static QArrayData *allocateData(qsizetype allocSize)
-{
- QArrayData *header = static_cast<QArrayData *>(::malloc(size_t(allocSize)));
- if (header) {
- header->ref_.storeRelaxed(1);
- header->flags = {};
- header->alloc = 0;
- }
- return header;
-}
-
namespace {
struct AllocationResult {
void *data;
@@ -178,12 +167,14 @@ allocateHelper(qsizetype objectSize, qsizetype alignment, qsizetype capacity,
if (Q_UNLIKELY(allocSize < 0)) // handle overflow. cannot allocate reliably
return {};
- QArrayData *header = allocateData(allocSize);
void *data = nullptr;
- if (header) {
+ QArrayData *header = static_cast<QArrayData *>(::malloc(size_t(allocSize)));
+ if (Q_LIKELY(header)) {
+ header->ref_.storeRelaxed(1);
+ header->flags = {};
// find where offset should point to so that data() is aligned to alignment bytes
data = QTypedArrayData<void>::dataStart(header, alignment);
- header->alloc = qsizetype(capacity);
+ header->alloc = capacity;
}
return { data, header };