summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qmetatype.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-04-01 11:29:22 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-04-03 12:20:55 +0200
commitb0e4d53b637e6c34457d14ed3f0be705098bf2f5 (patch)
treee652a5aa27e64839dfa1b0ac20c401d0075ac28c /src/corelib/kernel/qmetatype.cpp
parent168a02d4056efbef5c09d6d5810cf174412147c5 (diff)
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 <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'src/corelib/kernel/qmetatype.cpp')
-rw-r--r--src/corelib/kernel/qmetatype.cpp7
1 files 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);