QDBusSlotCache: Include flags into the hash key
This removes the need for doing two separate iteration to find entries in the hash. Also QMultyHash can now be replaced by plain QHash. Change-Id: Ie704e74c1dbb0c8e40d22a7cd572fcc8a3bfcd5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
9aaeb1bb3d
commit
588700dbfa
@ -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
|
||||
|
@ -46,18 +46,34 @@ struct QDBusSlotCache
|
||||
{
|
||||
struct Data
|
||||
{
|
||||
int flags;
|
||||
int slotIdx;
|
||||
QList<QMetaType> metaTypes;
|
||||
|
||||
void swap(Data &other) noexcept
|
||||
{
|
||||
qSwap(flags, other.flags);
|
||||
qSwap(slotIdx, other.slotIdx);
|
||||
qSwap(metaTypes, other.metaTypes);
|
||||
}
|
||||
};
|
||||
typedef QMultiHash<QString, Data> 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<Key, Data>;
|
||||
|
||||
Hash hash;
|
||||
|
||||
void swap(QDBusSlotCache &other) noexcept { qSwap(hash, other.hash); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user