Skip to content

Commit

Permalink
QMetaType: use the heterogeneous lookup feature of QHash when possible
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thiagomacieira committed Jan 18, 2025
1 parent 0d047ca commit bd57467
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/corelib/kernel/qmetatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit bd57467

Please sign in to comment.