From 6e8988c92626e870f90ac040fa307118ff77b06d Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 6 Apr 2023 15:13:59 +0200 Subject: [PATCH] CppModelManager: Use locator matcher for unused functions With this patch, when both cpp and lsp function filters are available, they now run in parallel. The execution time for getting the filter results (~110 K hits) for the Creator codebase went goes from ~1100 ms into ~650 ms. This patch also solves the potential issue with interference between parallel runs of functions filter in locator and in find unused functions. Change-Id: I8f7f0b85d325848c04760ab76a7b9f02bcb5991e Reviewed-by: Christian Kandeler --- src/plugins/cppeditor/cppmodelmanager.cpp | 29 +++++++++-------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp index 1e22d03d901..78e3453460c 100644 --- a/src/plugins/cppeditor/cppmodelmanager.cpp +++ b/src/plugins/cppeditor/cppmodelmanager.cpp @@ -65,7 +65,6 @@ #include #include #include -#include #include #include @@ -535,8 +534,8 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder) const auto actionsSwitcher = std::make_shared(); // Step 1: Employ locator to find all functions - ILocatorFilter *const functionsFilter = CppModelManager::instance()->functionsFilter(); - QTC_ASSERT(functionsFilter, return); + LocatorMatcher *matcher = new LocatorMatcher; + matcher->setTasks(LocatorMatcher::functionMatchers()); const QPointer search = SearchResultWindow::instance()->startNewSearch(Tr::tr("Find Unused Functions"), {}, @@ -544,25 +543,22 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder) SearchResultWindow::SearchOnly, SearchResultWindow::PreserveCaseDisabled, "CppEditor"); + matcher->setParent(search); connect(search, &SearchResult::activated, [](const SearchResultItem &item) { EditorManager::openEditorAtSearchResult(item); }); SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); - const auto locatorWatcher = new QFutureWatcher(search); - functionsFilter->prepareSearch({}); - connect(search, &SearchResult::canceled, locatorWatcher, [locatorWatcher] { - locatorWatcher->cancel(); - }); - connect(locatorWatcher, &QFutureWatcher::finished, search, - [locatorWatcher, search, folder, actionsSwitcher] { - locatorWatcher->deleteLater(); - if (locatorWatcher->isCanceled()) { + connect(search, &SearchResult::canceled, matcher, [matcher] { delete matcher; }); + connect(matcher, &LocatorMatcher::done, search, + [matcher, search, folder, actionsSwitcher](bool success) { + matcher->deleteLater(); + if (!success) { search->finishSearch(true); return; } Links links; - for (int i = 0; i < locatorWatcher->future().resultCount(); ++i) { - const LocatorFilterEntry &entry = locatorWatcher->resultAt(i); + const auto entries = matcher->outputData(); + for (const LocatorFilterEntry &entry : entries) { static const QStringList prefixBlacklist{"main(", "~", "qHash(", "begin()", "end()", "cbegin()", "cend()", "constBegin()", "constEnd()"}; if (Utils::anyOf(prefixBlacklist, [&entry](const QString &prefix) { @@ -614,10 +610,7 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder) for (int i = 0; i < inFlightCount; ++i) checkNextFunctionForUnused(search, findRefsFuture, actionsSwitcher); }); - locatorWatcher->setFuture( - Utils::runAsync([functionsFilter](QFutureInterface &future) { - future.reportResults(functionsFilter->matchesFor(future, {})); - })); + matcher->start(); } void CppModelManager::checkForUnusedSymbol(SearchResult *search,