From 1e0e16b5f3c0d4f3f78d5369b4dffedb03937481 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Wed, 31 May 2023 11:06:34 +0200 Subject: [PATCH] QVariant: Extract Method PrivateShared::computeOffset() Will be re-used in the upcoming emplace() function. No attempt is made to re-write the expression to be more readable. That's left for another commit. Task-number: QTBUG-112187 Change-Id: Id391b78f1477c5225beda8a32c4f6c1393dd51bb Reviewed-by: Fabian Kosmale Reviewed-by: Marc Mutz --- src/corelib/kernel/qvariant.h | 1 + src/corelib/kernel/qvariant_p.h | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index d93df46275..01646bca28 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -78,6 +78,7 @@ public: private: inline PrivateShared() : ref(1) { } public: + static int computeOffset(PrivateShared *ps, size_t align); static size_t computeAllocationSize(size_t size, size_t align); static PrivateShared *create(size_t size, size_t align); static void free(PrivateShared *p); diff --git a/src/corelib/kernel/qvariant_p.h b/src/corelib/kernel/qvariant_p.h index 8787f140f8..fef43dab03 100644 --- a/src/corelib/kernel/qvariant_p.h +++ b/src/corelib/kernel/qvariant_p.h @@ -34,6 +34,11 @@ customConstructShared(size_t size, size_t align, F &&construct) return ptr.release(); } +inline int QVariant::PrivateShared::computeOffset(PrivateShared *ps, size_t align) +{ + return int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps)); +} + inline size_t QVariant::PrivateShared::computeAllocationSize(size_t size, size_t align) { size += sizeof(PrivateShared); @@ -52,7 +57,7 @@ inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, siz size = computeAllocationSize(size, align); void *data = operator new(size); auto *ps = new (data) QVariant::PrivateShared(); - ps->offset = int(((quintptr(ps) + sizeof(PrivateShared) + align - 1) & ~(align - 1)) - quintptr(ps)); + ps->offset = computeOffset(ps, align); return ps; }