From 9c646d55cde151fc640dd8abf6aeccf9153cf5e9 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 29 Jan 2021 11:41:53 +0100 Subject: [PATCH] Move the BookmarkFilter's matching into the main thread We can't operate directly on the BookmarkManager and Bookmark instances in the other thread, as they may be freely modified in the gui thread in the same time. Since it's uncommon to have hundreds of bookmarks set, we prepare all the needed data in the main thread instead, which shouldn't slow down the locator significantly. Change-Id: I9df0a8425694632c40138fbe3667499f7fc03432 Reviewed-by: Eike Ziller --- src/plugins/bookmarks/bookmarkfilter.cpp | 19 ++++++++++++------- src/plugins/bookmarks/bookmarkfilter.h | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins/bookmarks/bookmarkfilter.cpp b/src/plugins/bookmarks/bookmarkfilter.cpp index ecaa90ff6ad..b0f162ff1d8 100644 --- a/src/plugins/bookmarks/bookmarkfilter.cpp +++ b/src/plugins/bookmarks/bookmarkfilter.cpp @@ -43,12 +43,11 @@ BookmarkFilter::BookmarkFilter(BookmarkManager *manager) setShortcutString("b"); } -QList BookmarkFilter::matchesFor(QFutureInterface &future, - const QString &entry) +void BookmarkFilter::prepareSearch(const QString &entry) { - Q_UNUSED(future) + m_results = {}; if (m_manager->rowCount() == 0) - return QList(); + return; auto match = [this](const QString &name, BookmarkManager::Roles role) { return m_manager->match(m_manager->index(0, 0), role, name, -1, @@ -74,7 +73,6 @@ QList BookmarkFilter::matchesFor(QFutureInterface entries; for (const QModelIndex &idx : matches) { const Bookmark *bookmark = m_manager->bookmarkForIndex(idx); const QString filename = bookmark->fileName().fileName(); @@ -112,9 +110,16 @@ QList BookmarkFilter::matchesFor(QFutureInterfaceicon(); - entries.append(filterEntry); + m_results.append(filterEntry); } - return entries; +} + +QList BookmarkFilter::matchesFor(QFutureInterface &future, + const QString &entry) +{ + Q_UNUSED(future) + Q_UNUSED(entry) + return m_results; } void BookmarkFilter::accept(LocatorFilterEntry selection, QString *newText, diff --git a/src/plugins/bookmarks/bookmarkfilter.h b/src/plugins/bookmarks/bookmarkfilter.h index ff378d9a908..da5102a5fe1 100644 --- a/src/plugins/bookmarks/bookmarkfilter.h +++ b/src/plugins/bookmarks/bookmarkfilter.h @@ -37,6 +37,7 @@ class BookmarkFilter : public Core::ILocatorFilter Q_OBJECT public: explicit BookmarkFilter(BookmarkManager *manager); + void prepareSearch(const QString &entry) override; QList matchesFor(QFutureInterface &future, const QString &entry) override; void accept(Core::LocatorFilterEntry selection, QString *newText, @@ -45,6 +46,7 @@ public: private: BookmarkManager *m_manager = nullptr; // not owned + QList m_results; }; } // namespace Internal