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>
bb10
Marc Mutz 2022-04-01 11:29:22 +02:00
parent 168a02d405
commit b0e4d53b63
1 changed files with 4 additions and 3 deletions

View File

@ -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);