From 011570285a22661e5d353cb8527392de01981a78 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 20 Jul 2022 13:55:24 -0700 Subject: [PATCH] QVariant: use QtMetaTypePrivate directly instead of QMetaType This suppresses a few duplicated checks that both QMetaType and QVariant has (and QVariant's are stricter), and allows for customConstruct() to perform a tail-call optimization, if it doesn't get inlined. Change-Id: I3859764fed084846bcb0fffd1703a503ffb01f8f Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qvariant.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 841c99bf49..9d89178428 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -256,6 +256,8 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant if (QVariant::Private::canUseInternalSpace(iface)) { d->is_shared = false; dst = &d->data; + if (!copy && !iface->defaultCtr) + return; // trivial default constructor, we've already memset } else { d->data.shared = QVariant::PrivateShared::create(iface); d->is_shared = true; @@ -263,17 +265,18 @@ static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant } // now ask QMetaType to construct for us - QMetaType(iface).construct(dst, copy); + construct(iface, dst, copy); } static void customClear(QVariant::Private *d) { - if (!d->typeInterface()) + const QtPrivate::QMetaTypeInterface *iface = d->typeInterface(); + if (!iface) return; if (!d->is_shared) { - d->type().destruct(d->data.data); + QtMetaTypePrivate::destruct(iface, d->data.data); } else { - d->type().destruct(d->data.shared->data()); + QtMetaTypePrivate::destruct(iface, d->data.shared->data()); QVariant::PrivateShared::free(d->data.shared); } }