From c1842d9aec4ecc71cc8918068edb1db79e0b621b Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sun, 28 Jan 2024 11:22:12 +0100 Subject: [PATCH] Command: Replace QMap with QHash The key is a pointer type. Get rid of 2 double lookups. Change-Id: I088325e7940091c9f8079bd466d8cbc37fd882e0 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/actionmanager/command.cpp | 16 +++++++++------- src/plugins/coreplugin/actionmanager/command_p.h | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp index 34fb37458f3..c48d55c30ef 100644 --- a/src/plugins/coreplugin/actionmanager/command.cpp +++ b/src/plugins/coreplugin/actionmanager/command.cpp @@ -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; } } diff --git a/src/plugins/coreplugin/actionmanager/command_p.h b/src/plugins/coreplugin/actionmanager/command_p.h index 6940be23fc6..18e3b5202c3 100644 --- a/src/plugins/coreplugin/actionmanager/command_p.h +++ b/src/plugins/coreplugin/actionmanager/command_p.h @@ -47,8 +47,8 @@ public: mutable std::unique_ptr m_touchBarAction; QString m_toolTip; - QMap > m_contextActionMap; - QMap m_scriptableMap; + QMap> m_contextActionMap; + QHash m_scriptableHash; bool m_active = false; bool m_contextInitialized = false; };