Command: Replace QMap with QHash

The key is a pointer type. Get rid of 2 double lookups.

Change-Id: I088325e7940091c9f8079bd466d8cbc37fd882e0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2024-01-28 11:22:12 +01:00
parent afb062cae2
commit c1842d9aec
2 changed files with 11 additions and 9 deletions

View File

@@ -398,7 +398,7 @@ void Internal::CommandPrivate::addOverrideAction(QAction *action,
m_contextActionMap.insert(id, action);
}
}
m_scriptableMap[action] = scriptable;
m_scriptableHash[action] = scriptable;
setCurrentContext(m_context);
}
@@ -434,18 +434,20 @@ bool Internal::CommandPrivate::isEmpty() const
bool Command::isScriptable() const
{
return std::find(d->m_scriptableMap.cbegin(), d->m_scriptableMap.cend(), true)
!= d->m_scriptableMap.cend();
return std::find(d->m_scriptableHash.cbegin(), d->m_scriptableHash.cend(), true)
!= d->m_scriptableHash.cend();
}
bool Command::isScriptable(const Context &context) const
{
if (context == d->m_context && d->m_scriptableMap.contains(d->m_action->action()))
return d->m_scriptableMap.value(d->m_action->action());
if (context == d->m_context) {
const auto it = d->m_scriptableHash.constFind(d->m_action->action());
if (it != d->m_scriptableHash.constEnd())
return *it;
}
for (int i = 0; i < context.size(); ++i) {
if (QAction *a = d->m_contextActionMap.value(context.at(i), nullptr)) {
if (d->m_scriptableMap.contains(a) && d->m_scriptableMap.value(a))
if (d->m_scriptableHash.value(a, false))
return true;
}
}

View File

@@ -47,8 +47,8 @@ public:
mutable std::unique_ptr<Utils::ProxyAction> m_touchBarAction;
QString m_toolTip;
QMap<Utils::Id, QPointer<QAction> > m_contextActionMap;
QMap<QAction*, bool> m_scriptableMap;
QMap<Utils::Id, QPointer<QAction>> m_contextActionMap;
QHash<QAction *, bool> m_scriptableHash;
bool m_active = false;
bool m_contextInitialized = false;
};