diff --git a/src/registry/cachingsearchstrategy.cpp b/src/registry/cachingsearchstrategy.cpp index 1b6a16119..554d3c7f5 100644 --- a/src/registry/cachingsearchstrategy.cpp +++ b/src/registry/cachingsearchstrategy.cpp @@ -22,16 +22,18 @@ ****************************************************************************/ #include "cachingsearchstrategy.h" -#include "docset.h" -#include "searchresult.h" +#include "docset.h" #include "searchquery.h" +#include "searchresult.h" using namespace Zeal; +const int CacheSize = 10; + CachingSearchStrategy::CachingSearchStrategy(std::unique_ptr strategy) - : m_search(std::move(strategy)), - m_cache(CachingSearchStrategy::CacheSize) + : m_search(std::move(strategy)) + , m_cache(CacheSize) { } diff --git a/src/registry/cachingsearchstrategy.h b/src/registry/cachingsearchstrategy.h index 38bb54ee5..2c91786ab 100644 --- a/src/registry/cachingsearchstrategy.h +++ b/src/registry/cachingsearchstrategy.h @@ -54,8 +54,6 @@ class CachingSearchStrategy : public DocsetSearchStrategy QList searchWithCache(const QString &query, const QString &prefix); QList searchWithoutCache(const QString &query, CancellationToken token); - const static int CacheSize = 10; - std::unique_ptr m_search; QCache > m_cache; }; diff --git a/src/registry/docset.cpp b/src/registry/docset.cpp index f600fc75a..9a2656555 100644 --- a/src/registry/docset.cpp +++ b/src/registry/docset.cpp @@ -482,7 +482,6 @@ void Docset::countSymbols() const QString symbolType = parseSymbolType(symbolTypeStr); m_symbolStrings.insertMulti(symbolType, symbolTypeStr); m_symbolCounts[symbolType] += query.value(1).toInt(); - m_symbolsTotal += query.value(1).toInt(); } } diff --git a/src/registry/docset.h b/src/registry/docset.h index 9634f2fd8..a1e0f2cac 100644 --- a/src/registry/docset.h +++ b/src/registry/docset.h @@ -108,7 +108,6 @@ class Docset QMap m_symbolStrings; QMap m_symbolCounts; mutable QMap> m_symbols; - uint64_t m_symbolsTotal; std::unique_ptr m_searchStrategy; }; diff --git a/src/registry/docsetregistry.cpp b/src/registry/docsetregistry.cpp index 47d1ff1ef..e335adc23 100644 --- a/src/registry/docsetregistry.cpp +++ b/src/registry/docsetregistry.cpp @@ -25,6 +25,8 @@ #include "searchresult.h" +#include +#include #include #include #include @@ -127,24 +129,26 @@ void DocsetRegistry::_addDocset(const QString &path) void DocsetRegistry::search(const QString &query, CancellationToken token) { qRegisterMetaType("CancellationToken"); - qRegisterMetaType("Zeal::CancellationToken"); QMetaObject::invokeMethod(this, "_runQueryAsync", Qt::QueuedConnection, Q_ARG(QString, query), Q_ARG(CancellationToken, token)); } -void DocsetRegistry::_runQueryAsync(const QString &query, const CancellationToken token) +void MergeQueryResults(QList &finalResult, const QList &partial) { - QList results; - - for (Docset *docset : docsets()) { - if (token.isCancelled()) - return; - results += docset->search(query, token); - } + finalResult += partial; +} +void DocsetRegistry::_runQueryAsync(const QString &query, const CancellationToken token) +{ + QFuture > queryResultsFuture = QtConcurrent::mappedReduced( + docsets(), + std::bind(&Docset::search, std::placeholders::_1, query, token), + &MergeQueryResults); + QList results = queryResultsFuture.result(); std::sort(results.begin(), results.end()); - emit queryCompleted(results); + if (!token.isCancelled()) + emit queryCompleted(results); } // Recursively finds and adds all docsets in a given directory. diff --git a/src/src.pro b/src/src.pro index 767f6c162..3c6484c92 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,6 +1,6 @@ TEMPLATE = app -QT += gui widgets sql +QT += gui widgets sql concurrent CONFIG += c++11 silent ## Build options