diff --git a/src/document/katedocument.h b/src/document/katedocument.h --- a/src/document/katedocument.h +++ b/src/document/katedocument.h @@ -140,7 +140,7 @@ QList views() const Q_DECL_OVERRIDE { - return m_views.keys(); + return m_viewsCache; } virtual KTextEditor::View *activeView() const @@ -1405,6 +1405,10 @@ * trigger a close of this document in the application */ void closeDocumentInApplication(); +private: + // To calculate a QHash.keys() is quite expensive, + // better keep a copy of that list updated when a view is added or removed. + QList m_viewsCache; }; #endif diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -2832,6 +2832,7 @@ { Q_ASSERT (!m_views.contains(view)); m_views.insert(view, static_cast(view)); + m_viewsCache.append(view); // apply the view & renderer vars from the file type if (!m_fileType.isEmpty()) { @@ -2848,6 +2849,7 @@ { Q_ASSERT (m_views.contains(view)); m_views.remove(view); + m_viewsCache.removeAll(view); if (activeView() == view) { setActiveView(nullptr);