From 8738d9a6a861f79df83e563db41e8b95adeed14a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 20 Jul 2022 13:36:46 -0700 Subject: QVariant: move the check for std::nullptr_t a bit up in customConstruct Avoids having to do work after QMetaType::construct() returns. That can't get the tail-call optimization right now because it is a non- inline non-static member function, so the QMetaType must be spilled to the stack. Change-Id: I3859764fed084846bcb0fffd1703a3ffc723f43f Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qvariant.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/corelib/kernel/qvariant.cpp') diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index f3c6305432..841c99bf49 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -218,7 +218,7 @@ static bool isValidMetaTypeForVariant(const QtPrivate::QMetaTypeInterface *iface if (!iface || iface->size == 0) return false; - Q_ASSERT(!isVoid(iface)); // only void should have size 0 + Q_ASSERT(!isInterfaceFor(iface)); // only void should have size 0 if (!isCopyConstructible(iface) || !isDestructible(iface)) { // all meta types must be copyable (because QVariant is) and // destructible (because QVariant owns it) @@ -243,11 +243,15 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant using namespace QtMetaTypePrivate; Q_ASSERT(iface); Q_ASSERT(iface->size); - Q_ASSERT(!isVoid(iface)); + Q_ASSERT(!isInterfaceFor(iface)); Q_ASSERT(isCopyConstructible(iface)); Q_ASSERT(isDestructible(iface)); Q_ASSERT(copy || isDefaultConstructible(iface)); + // need to check for nullptr_t here, as this can get called by fromValue(nullptr). fromValue() uses + // std::addressof(value) which in this case returns the address of the nullptr object. + d->is_null = !copy || isInterfaceFor(iface); + void *dst; if (QVariant::Private::canUseInternalSpace(iface)) { d->is_shared = false; @@ -260,10 +264,6 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant // now ask QMetaType to construct for us QMetaType(iface).construct(dst, copy); - - // need to check for nullptr_t here, as this can get called by fromValue(nullptr). fromValue() uses - // std::addressof(value) which in this case returns the address of the nullptr object. - d->is_null = !copy || QMetaType(iface) == QMetaType::fromType(); } static void customClear(QVariant::Private *d) -- cgit v1.2.3