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

Put the DependencyTable calculation into the QFuture.

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