From b0e4d53b637e6c34457d14ed3f0be705098bf2f5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 1 Apr 2022 11:29:22 +0200 Subject: [PATCH] QMetaType: don't create a registry just to query its emptiness The function-call operator of QGlobalStatic creates the payload object unless is has already been deleted. When performing read-only operations on the payload object, it's better to use QGlobalStatic::exists() + the dereference operator instead, because that prevents the creation of the payload just to find it empty. Pick-to: 6.3 Change-Id: I367add516520d076412cbbc542ee7a3b6ea45c14 Reviewed-by: Fabian Kosmale Reviewed-by: Qt CI Bot --- src/corelib/kernel/qmetatype.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index c0bc82ed29..cd71805e12 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -2580,7 +2580,8 @@ static inline int qMetaTypeStaticType(const char *typeName, int length) */ static int qMetaTypeCustomType_unlocked(const char *typeName, int length) { - if (auto reg = customTypeRegistry()) { + if (customTypeRegistry.exists()) { + auto reg = &*customTypeRegistry; #if QT_CONFIG(thread) Q_ASSERT(!reg->lock.tryLockForWrite()); #endif @@ -2980,8 +2981,8 @@ static const QtPrivate::QMetaTypeInterface *interfaceForType(int typeId) { const QtPrivate::QMetaTypeInterface *iface = nullptr; if (typeId >= QMetaType::User) { - if (auto reg = customTypeRegistry()) - iface = reg->getCustomType(typeId); + if (customTypeRegistry.exists()) + iface = customTypeRegistry->getCustomType(typeId); } else { if (auto moduleHelper = qModuleHelperForType(typeId)) iface = moduleHelper->interfaceForType(typeId);