From fe9051c25da20e4edea33178a99c7a164af580fc Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 28 Jan 2021 17:10:11 +0100 Subject: [PATCH] ClangCurrentDocumentFilter: make use of prepareSearch function Since it's guaranteed, that prepareSearch() is always called from the main thread prior to the call to matchesFor() from the other thread, we copy the data inside prepareSearch() which we will operate on when matchesFor() is called later on. Change-Id: Idf6a8e683356bb524eb4b5b1ce1e05b0ba065c8b Reviewed-by: Eike Ziller --- .../clangcurrentdocumentfilter.cpp | 23 +++++++++++-------- .../clangcurrentdocumentfilter.h | 4 +++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp index dbe9737c847..395babd6e33 100644 --- a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp +++ b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.cpp @@ -97,11 +97,17 @@ static Core::LocatorFilterEntry makeEntry(Core::ILocatorFilter *filter, return entry; } +void ClangCurrentDocumentFilter::prepareSearch(const QString &entry) +{ + Q_UNUSED(entry) + m_preparedPath = m_currentPath; +} + QList ClangCurrentDocumentFilter::matchesFor( QFutureInterface &, const QString &entry) { QList goodEntries; - if (!m_currentEditor) + if (m_preparedPath.isEmpty()) return goodEntries; FuzzyMatcher::CaseSensitivity caseSesitivity = caseSensitivity(entry) == Qt::CaseSensitive @@ -111,7 +117,7 @@ QList ClangCurrentDocumentFilter::matchesFor( if (!regexp.isValid()) return goodEntries; - ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_currentPath); + ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(m_preparedPath); if (!processor) return goodEntries; @@ -143,10 +149,10 @@ void ClangCurrentDocumentFilter::refresh(QFutureInterface &) { } -void ClangCurrentDocumentFilter::reset() +void ClangCurrentDocumentFilter::reset(Core::IEditor *newCurrent, const QString &path) { - m_currentEditor = nullptr; - m_currentPath.clear(); + m_currentEditor = newCurrent; + m_currentPath = path; } void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAboutToClose) @@ -161,11 +167,10 @@ void ClangCurrentDocumentFilter::onEditorAboutToClose(Core::IEditor *editorAbout void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurrent) { if (newCurrent) { - m_currentEditor = newCurrent; - Core::IDocument *document = m_currentEditor->document(); - QTC_ASSERT(document, return;); + Core::IDocument *document = newCurrent->document(); + QTC_ASSERT(document, reset(); return); if (auto *textDocument = qobject_cast(document)) { - m_currentPath = textDocument->filePath().toString(); + reset(newCurrent, textDocument->filePath().toString()); return; } } diff --git a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h index 891905fbda0..bd758d74cd5 100644 --- a/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h +++ b/src/plugins/clangcodemodel/clangcurrentdocumentfilter.h @@ -39,6 +39,7 @@ class ClangCurrentDocumentFilter : public Core::ILocatorFilter public: explicit ClangCurrentDocumentFilter(); + void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) override; void accept(Core::LocatorFilterEntry selection, @@ -48,10 +49,11 @@ private: void onEditorAboutToClose(Core::IEditor *editors); void onCurrentEditorChanged(Core::IEditor *newCurrent); - void reset(); + void reset(Core::IEditor *newCurrent = nullptr, const QString &path = QString()); Core::IEditor *m_currentEditor = nullptr; QString m_currentPath; + QString m_preparedPath; }; } // namespace Internal