forked from qt-creator/qt-creator
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:
@@ -398,7 +398,7 @@ void Internal::CommandPrivate::addOverrideAction(QAction *action,
|
|||||||
m_contextActionMap.insert(id, action);
|
m_contextActionMap.insert(id, action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_scriptableMap[action] = scriptable;
|
m_scriptableHash[action] = scriptable;
|
||||||
setCurrentContext(m_context);
|
setCurrentContext(m_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,18 +434,20 @@ bool Internal::CommandPrivate::isEmpty() const
|
|||||||
|
|
||||||
bool Command::isScriptable() const
|
bool Command::isScriptable() const
|
||||||
{
|
{
|
||||||
return std::find(d->m_scriptableMap.cbegin(), d->m_scriptableMap.cend(), true)
|
return std::find(d->m_scriptableHash.cbegin(), d->m_scriptableHash.cend(), true)
|
||||||
!= d->m_scriptableMap.cend();
|
!= d->m_scriptableHash.cend();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Command::isScriptable(const Context &context) const
|
bool Command::isScriptable(const Context &context) const
|
||||||
{
|
{
|
||||||
if (context == d->m_context && d->m_scriptableMap.contains(d->m_action->action()))
|
if (context == d->m_context) {
|
||||||
return d->m_scriptableMap.value(d->m_action->action());
|
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) {
|
for (int i = 0; i < context.size(); ++i) {
|
||||||
if (QAction *a = d->m_contextActionMap.value(context.at(i), nullptr)) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -47,8 +47,8 @@ public:
|
|||||||
mutable std::unique_ptr<Utils::ProxyAction> m_touchBarAction;
|
mutable std::unique_ptr<Utils::ProxyAction> m_touchBarAction;
|
||||||
QString m_toolTip;
|
QString m_toolTip;
|
||||||
|
|
||||||
QMap<Utils::Id, QPointer<QAction> > m_contextActionMap;
|
QMap<Utils::Id, QPointer<QAction>> m_contextActionMap;
|
||||||
QMap<QAction*, bool> m_scriptableMap;
|
QHash<QAction *, bool> m_scriptableHash;
|
||||||
bool m_active = false;
|
bool m_active = false;
|
||||||
bool m_contextInitialized = false;
|
bool m_contextInitialized = false;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user