From bd57467f4e314fe274ccbd279f1972e160eb1cc4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 27 Aug 2024 10:39:45 -0700 Subject: [PATCH] QMetaType: use the heterogeneous lookup feature of QHash when possible This probably doesn't make a difference because QByteArray::fromRawData is inline, does not allocate memory, and (as of the last commit) noexcept. As an beneficial side-effect, we get to test that feature in QtCore's own build. Change-Id: Ifd19cfdba83064bbf4d3fffdd032622ec102e234 Reviewed-by: Marc Mutz --- src/corelib/kernel/qmetatype.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index a17245044fc..682a31ad13b 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -2742,12 +2742,19 @@ static inline int qMetaTypeStaticType(const char *typeName, int length) */ static int qMetaTypeCustomType_unlocked(const char *typeName, int length) { + auto type = [&] { +#ifdef __cpp_concepts + return QByteArrayView(typeName, length); +#else + return QByteArray::fromRawData(typeName, length); +#endif + }; if (customTypeRegistry.exists()) { auto reg = &*customTypeRegistry; #if QT_CONFIG(thread) Q_ASSERT(!reg->lock.tryLockForWrite()); #endif - if (auto ti = reg->aliases.value(QByteArray::fromRawData(typeName, length), nullptr)) { + if (auto ti = reg->aliases.value(type(), nullptr)) { return ti->typeId.loadRelaxed(); } }