QmlDesigner: Cache result of eventListEnabled

Calling EventList::hasEventListModel() takes time, since it includes
file access. Since eventListEnabled() is called on each selection change,
we cache the result. If the root node is the same, also the document is the
same and there is no reason to check again.
This way we check only once per document.

Change-Id: Id664811b1319a306c70283d2b37de258a129892f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Knud Dollereder <knud.dollereder@qt.io>
This commit is contained in:
Thomas Hartmann
2022-02-18 13:44:12 +01:00
parent a29154225e
commit 4cbe956722

View File

@@ -33,9 +33,18 @@
namespace QmlDesigner {
inline bool eventListEnabled(const SelectionContext &)
inline bool eventListEnabled(const SelectionContext &context)
{
return EventList::hasEventListModel();
static ModelNode lastRootNode;
static bool lastValue = false;
if (lastRootNode == context.rootNode())
return lastValue;
lastRootNode = context.rootNode();
lastValue = EventList::hasEventListModel();
return lastValue;
}
QIcon eventListIconFromIconFont(Theme::Icon iconType)