diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 5cef94216ba..ed5d424ae4c 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -857,19 +857,15 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu cacheKey += signature; } - QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(cacheKey); - while (cacheIt != slotCache.hash.constEnd() && cacheIt->flags != flags && - cacheIt.key() == cacheKey) - ++cacheIt; - if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey) - { + QDBusSlotCache::Key compoundKey{ std::move(cacheKey), flags }; + QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(compoundKey); + if (cacheIt == slotCache.hash.constEnd()) { // not cached, analyze the meta object const QMetaObject *mo = object->metaObject(); QByteArray memberName = msg.member().toUtf8(); // find a slot that matches according to the rules above QDBusSlotCache::Data slotData; - slotData.flags = flags; slotData.slotIdx = ::findSlot(mo, memberName, flags, msg.signature(), slotData.metaTypes); if (slotData.slotIdx == -1) { // ### this is where we want to add the connection as an arg too @@ -881,7 +877,7 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu // save the negative lookup slotData.slotIdx = -1; slotData.metaTypes.clear(); - slotCache.hash.insert(cacheKey, slotData); + slotCache.hash.insert(compoundKey, slotData); object->setProperty(cachePropertyName, QVariant::fromValue(slotCache)); qCWarning(dbusIntegration).nospace() << "Could not find slot " << mo->className() @@ -891,7 +887,7 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu } // save to the cache - slotCache.hash.insert(cacheKey, slotData); + slotCache.hash.insert(compoundKey, slotData); object->setProperty(cachePropertyName, QVariant::fromValue(slotCache)); // found the slot to be called diff --git a/src/dbus/qdbusintegrator_p.h b/src/dbus/qdbusintegrator_p.h index ab5dba5d292..774fb79d0be 100644 --- a/src/dbus/qdbusintegrator_p.h +++ b/src/dbus/qdbusintegrator_p.h @@ -46,18 +46,34 @@ struct QDBusSlotCache { struct Data { - int flags; int slotIdx; QList metaTypes; void swap(Data &other) noexcept { - qSwap(flags, other.flags); qSwap(slotIdx, other.slotIdx); qSwap(metaTypes, other.metaTypes); } }; - typedef QMultiHash Hash; + + struct Key + { + QString memberWithSignature; + int flags; + + friend bool operator==(const Key &lhs, const Key &rhs) noexcept + { + return lhs.memberWithSignature == rhs.memberWithSignature && lhs.flags == rhs.flags; + } + + friend size_t qHash(const QDBusSlotCache::Key &key, size_t seed = 0) noexcept + { + return qHashMulti(seed, key.memberWithSignature, key.flags); + } + }; + + using Hash = QHash; + Hash hash; void swap(QDBusSlotCache &other) noexcept { qSwap(hash, other.hash); }