Commit 284b8d38 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Put the DependencyTable calculation into the QFuture.

Done-with: Roberto Raggi
parent 1cc5e1fe
...@@ -74,9 +74,7 @@ QHash<QString, QStringList> DependencyTable::dependencyTable() const ...@@ -74,9 +74,7 @@ QHash<QString, QStringList> DependencyTable::dependencyTable() const
bool DependencyTable::isValidFor(const Snapshot &snapshot) const bool DependencyTable::isValidFor(const Snapshot &snapshot) const
{ {
const int documentCount = snapshot.size(); const int documentCount = snapshot.size();
if (documentCount != files.size() if (documentCount != files.size())
|| documentCount != includesPerFile.size()
|| documentCount != includeMap.size())
return false; return false;
for (Snapshot::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it) { for (Snapshot::const_iterator it = snapshot.begin(); it != snapshot.end(); ++it) {
...@@ -93,6 +91,12 @@ bool DependencyTable::isValidFor(const Snapshot &snapshot) const ...@@ -93,6 +91,12 @@ bool DependencyTable::isValidFor(const Snapshot &snapshot) const
void DependencyTable::build(const Snapshot &snapshot) void DependencyTable::build(const Snapshot &snapshot)
{ {
includesPerFile.clear();
files.clear();
fileIndex.clear();
includes.clear();
includeMap.clear();
const int documentCount = snapshot.size(); const int documentCount = snapshot.size();
files.resize(documentCount); files.resize(documentCount);
includeMap.resize(documentCount); includeMap.resize(documentCount);
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include <cplusplus/Overview.h> #include <cplusplus/Overview.h>
#include <QtCore/QTime> #include <QtCore/QTime>
#include <QtCore/QTimer>
#include <QtCore/QtConcurrentRun> #include <QtCore/QtConcurrentRun>
#include <QtCore/QtConcurrentMap> #include <QtCore/QtConcurrentMap>
#include <QtCore/QDir> #include <QtCore/QDir>
...@@ -154,6 +155,14 @@ CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelMa ...@@ -154,6 +155,14 @@ CppFindReferences::CppFindReferences(CppTools::CppModelManagerInterface *modelMa
m_watcher.setPendingResultsLimit(1); m_watcher.setPendingResultsLimit(1);
connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int))); connect(&m_watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(displayResults(int,int)));
connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished())); connect(&m_watcher, SIGNAL(finished()), this, SLOT(searchFinished()));
m_updateDependencyTableTimer = new QTimer(this);
m_updateDependencyTableTimer->setSingleShot(true);
m_updateDependencyTableTimer->setInterval(2000);
connect(m_updateDependencyTableTimer, SIGNAL(timeout()),
this, SLOT(updateDependencyTable()));
connect(modelManager, SIGNAL(documentUpdated(CPlusPlus::Document::Ptr)),
m_updateDependencyTableTimer, SLOT(start()));
} }
CppFindReferences::~CppFindReferences() CppFindReferences::~CppFindReferences()
...@@ -216,13 +225,20 @@ static void find_helper(QFutureInterface<Usage> &future, ...@@ -216,13 +225,20 @@ static void find_helper(QFutureInterface<Usage> &future,
future.setProgressValue(files.size()); future.setProgressValue(files.size());
} }
void CppFindReferences::updateDependencyTable(const Snapshot &snapshot) static CPlusPlus::DependencyTable dependencyTable(DependencyTable previous, CPlusPlus::Snapshot snapshot)
{ {
if (!m_deps.isValidFor(snapshot)) { if (previous.isValidFor(snapshot))
DependencyTable newDeps; return previous;
newDeps.build(snapshot);
m_deps = newDeps; DependencyTable table;
} table.build(snapshot);
return table;
}
void CppFindReferences::updateDependencyTable()
{
m_depsFuture.cancel();
m_depsFuture = QtConcurrent::run(&dependencyTable, m_deps, _modelManager->snapshot());
} }
void CppFindReferences::findUsages(Document::Ptr symbolDocument, Symbol *symbol) void CppFindReferences::findUsages(Document::Ptr symbolDocument, Symbol *symbol)
...@@ -265,7 +281,8 @@ void CppFindReferences::findAll_helper(Document::Ptr symbolDocument, Symbol *sym ...@@ -265,7 +281,8 @@ void CppFindReferences::findAll_helper(Document::Ptr symbolDocument, Symbol *sym
Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager(); Core::ProgressManager *progressManager = Core::ICore::instance()->progressManager();
updateDependencyTable(snapshot); updateDependencyTable(); // ensure the dependency table is updated
m_deps = m_depsFuture;
QFuture<Usage> result; QFuture<Usage> result;
...@@ -424,7 +441,8 @@ void CppFindReferences::findMacroUses(const Macro &macro) ...@@ -424,7 +441,8 @@ void CppFindReferences::findMacroUses(const Macro &macro)
source.mid(macro.offset(), macro.length()), 0, macro.length()); source.mid(macro.offset(), macro.length()), 0, macro.length());
} }
updateDependencyTable(snapshot); updateDependencyTable(); // ensure the dependency table is updated
m_deps = m_depsFuture;
QFuture<Usage> result; QFuture<Usage> result;
result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, m_deps, macro); result = QtConcurrent::run(&findMacroUses_helper, workingCopy, snapshot, m_deps, macro);
......
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
#include <cplusplus/DependencyTable.h> #include <cplusplus/DependencyTable.h>
#include <cplusplus/FindUsages.h> #include <cplusplus/FindUsages.h>
QT_FORWARD_DECLARE_CLASS(QTimer)
namespace Find { namespace Find {
class SearchResultWindow; class SearchResultWindow;
struct SearchResultItem; struct SearchResultItem;
...@@ -75,16 +77,18 @@ private Q_SLOTS: ...@@ -75,16 +77,18 @@ private Q_SLOTS:
void searchFinished(); void searchFinished();
void openEditor(const Find::SearchResultItem &item); void openEditor(const Find::SearchResultItem &item);
void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items); void onReplaceButtonClicked(const QString &text, const QList<Find::SearchResultItem> &items);
void updateDependencyTable();
private: private:
void findAll_helper(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol); void findAll_helper(CPlusPlus::Document::Ptr symbolDocument, CPlusPlus::Symbol *symbol);
void updateDependencyTable(const CPlusPlus::Snapshot &snapshot);
private: private:
QPointer<CppModelManagerInterface> _modelManager; QPointer<CppModelManagerInterface> _modelManager;
Find::SearchResultWindow *_resultWindow; Find::SearchResultWindow *_resultWindow;
QFutureWatcher<CPlusPlus::Usage> m_watcher; QFutureWatcher<CPlusPlus::Usage> m_watcher;
CPlusPlus::DependencyTable m_deps; CPlusPlus::DependencyTable m_deps;
QFuture<CPlusPlus::DependencyTable> m_depsFuture;
QTimer *m_updateDependencyTableTimer;
}; };
} // end of namespace Internal } // end of namespace Internal
......
...@@ -131,7 +131,6 @@ public: ...@@ -131,7 +131,6 @@ public:
Q_SIGNALS: Q_SIGNALS:
void projectPathChanged(const QString &projectPath); void projectPathChanged(const QString &projectPath);
void documentUpdated(CPlusPlus::Document::Ptr doc);
void aboutToRemoveFiles(const QStringList &files); void aboutToRemoveFiles(const QStringList &files);
public Q_SLOTS: public Q_SLOTS:
......
...@@ -127,6 +127,9 @@ public: ...@@ -127,6 +127,9 @@ public:
virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0; virtual void findMacroUsages(const CPlusPlus::Macro &macro) = 0;
Q_SIGNALS:
void documentUpdated(CPlusPlus::Document::Ptr doc);
public Q_SLOTS: public Q_SLOTS:
void updateModifiedSourceFiles(); void updateModifiedSourceFiles();
virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles) = 0; virtual QFuture<void> updateSourceFiles(const QStringList &sourceFiles) = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment