From ed7d59c0a266bf578c3a9203c0107ab2ed29f067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Brooke?= Date: Fri, 24 Jan 2025 17:08:15 +0100 Subject: [PATCH] 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 --- src/corelib/tools/qarraydata.cpp | 19 +++++-------------- 1 file 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(::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(::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::dataStart(header, alignment); - header->alloc = qsizetype(capacity); + header->alloc = capacity; } return { data, header };