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 <marc.mutz@qt.io>
This commit is contained in:
Thiago Macieira 2024-08-27 10:39:45 -07:00
parent 0d047ca713
commit bd57467f4e

View File

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