diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-07-22 22:22:48 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-08-03 19:51:25 -0700 |
commit | cfa955040c8543cb95fc5fe040c20b46af73c96b (patch) | |
tree | 52f6c4d02b643b556fe794f2405f91e7843096ac /src/corelib/kernel/qvariant.cpp | |
parent | 392e44539329017b04757e664400afaa7aacf7f5 (diff) |
QVariant: pass the size and alignment to PrivateShared::create()
Instead of having that function load those from memory. This allows us
to pass constant expressions in QVariant::Private s constructor
Change-Id: I3859764fed084846bcb0fffd17045ddd62553710
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/kernel/qvariant.cpp')
-rw-r--r-- | src/corelib/kernel/qvariant.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index b7450cbafa..8f413b52e0 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -236,7 +236,7 @@ static bool isValidMetaTypeForVariant(const QtPrivate::QMetaTypeInterface *iface } template <typename F> static QVariant::PrivateShared * -customConstructShared(const QtPrivate::QMetaTypeInterface *iface, F &&construct) +customConstructShared(size_t size, size_t align, F &&construct) { struct Deleter { void operator()(QVariant::PrivateShared *p) const @@ -245,7 +245,7 @@ customConstructShared(const QtPrivate::QMetaTypeInterface *iface, F &&construct) // this is exception-safe std::unique_ptr<QVariant::PrivateShared, Deleter> ptr; - ptr.reset(QVariant::PrivateShared::create(iface)); + ptr.reset(QVariant::PrivateShared::create(size, align)); construct(ptr->data()); return ptr.release(); } @@ -273,7 +273,7 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant return; // trivial default constructor, we've already memset construct(iface, d->data.data, copy); } else { - d->data.shared = customConstructShared(iface, [=](void *where) { + d->data.shared = customConstructShared(iface->size, iface->alignment, [=](void *where) { construct(iface, where, copy); }); d->is_shared = true; @@ -310,13 +310,8 @@ static QVariant::Private clonePrivate(const QVariant::Private &other) } // anonymous used to hide QVariant handlers -inline QVariant::PrivateShared * -QVariant::PrivateShared::create(const QtPrivate::QMetaTypeInterface *type) +inline QVariant::PrivateShared *QVariant::PrivateShared::create(size_t size, size_t align) { - Q_ASSERT(type); - size_t size = type->size; - size_t align = type->alignment; - size += sizeof(PrivateShared); if (align > sizeof(PrivateShared)) { // The alignment is larger than the alignment we can guarantee for the pointer @@ -362,7 +357,7 @@ QVariant::Private::Private(std::piecewise_construct_t, const T &t) new (data.data) T(t); } else { static_assert(!isNothrowQVariantConstructible); // we allocate memory, even if T doesn't - data.shared = customConstructShared(iface, [=](void *where) { + data.shared = customConstructShared(sizeof(T), alignof(T), [=](void *where) { new (where) T(t); }); } |