summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppfindreferences.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2009-12-04 13:04:20 +0100
committerRoberto Raggi <roberto.raggi@nokia.com>2009-12-04 13:04:47 +0100
commitaae5b92125a47bf616760d0c7570502bb9c31368 (patch)
treef3e7dfe76a2bb3e8591491ad59ebbfc7deb0e2f2 /src/plugins/cpptools/cppfindreferences.cpp
parent425c61f6245240c0d6ee2d06c55d4cdd591fb3c4 (diff)
downloadqt-creator-aae5b92125a47bf616760d0c7570502bb9c31368.tar.gz
Use mappedReduce when searching for the usages of a symbol.
Diffstat (limited to 'src/plugins/cpptools/cppfindreferences.cpp')
-rw-r--r--src/plugins/cpptools/cppfindreferences.cpp121
1 files changed, 78 insertions, 43 deletions
diff --git a/src/plugins/cpptools/cppfindreferences.cpp b/src/plugins/cpptools/cppfindreferences.cpp
index a1f9a31dc1..b7a1cdc89d 100644
--- a/src/plugins/cpptools/cppfindreferences.cpp
+++ b/src/plugins/cpptools/cppfindreferences.cpp
@@ -54,10 +54,13 @@
#include <QtCore/QTime>
#include <QtCore/QtConcurrentRun>
+#include <QtCore/QtConcurrentMap>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <qtconcurrent/runextensions.h>
+#include <functional>
+
using namespace CppTools::Internal;
using namespace CPlusPlus;
@@ -81,7 +84,7 @@ QList<int> CppFindReferences::references(Symbol *symbol,
{
QList<int> references;
- FindUsages findUsages(doc, snapshot, /*future = */ 0);
+ FindUsages findUsages(doc, snapshot);
findUsages.setGlobalNamespaceBinding(bind(doc, snapshot));
findUsages(symbol);
references = findUsages.references();
@@ -89,6 +92,77 @@ QList<int> CppFindReferences::references(Symbol *symbol,
return references;
}
+class MyProcess: public std::unary_function<QString, QList<Usage> >
+{
+ const QMap<QString, QString> wl;
+ const Snapshot snapshot;
+ Symbol *symbol;
+
+public:
+ MyProcess(const QMap<QString, QString> wl,
+ const Snapshot snapshot,
+ Symbol *symbol)
+ : wl(wl), snapshot(snapshot), symbol(symbol)
+ { }
+
+ QList<Usage> operator()(const QString &fileName)
+ {
+ QList<Usage> usages;
+ const Identifier *symbolId = symbol->identifier();
+
+ if (Document::Ptr previousDoc = snapshot.value(fileName)) {
+ Control *control = previousDoc->control();
+ if (! control->findIdentifier(symbolId->chars(), symbolId->size()))
+ return usages; // skip this document, it's not using symbolId.
+ }
+
+ QByteArray source;
+
+ if (wl.contains(fileName))
+ source = snapshot.preprocessedCode(wl.value(fileName), fileName);
+ else {
+ QFile file(fileName);
+ if (! file.open(QFile::ReadOnly))
+ return usages;
+
+ const QString contents = QTextStream(&file).readAll(); // ### FIXME
+ source = snapshot.preprocessedCode(contents, fileName);
+ }
+
+ Document::Ptr doc = snapshot.documentFromSource(source, fileName);
+ doc->tokenize();
+
+ Control *control = doc->control();
+ if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) {
+ doc->check();
+
+ FindUsages process(doc, snapshot);
+ process.setGlobalNamespaceBinding(bind(doc, snapshot));
+
+ process(symbol);
+ usages = process.usages();
+ }
+
+ return usages;
+ }
+};
+
+class MyReduce: public std::binary_function<QList<Usage> &, QList<Usage>, void>
+{
+ QFutureInterface<Usage> *future;
+
+public:
+ MyReduce(QFutureInterface<Usage> *future): future(future) {}
+
+ void operator()(QList<Usage> &uu, const QList<Usage> &usages)
+ {
+ foreach (const Usage &u, usages)
+ future->reportResult(u);
+
+ future->setProgressValue(future->progressValue() + 1);
+ }
+};
+
static void find_helper(QFutureInterface<Usage> &future,
const QMap<QString, QString> wl,
Snapshot snapshot,
@@ -121,49 +195,10 @@ static void find_helper(QFutureInterface<Usage> &future,
future.setProgressRange(0, files.size());
- for (int i = 0; i < files.size(); ++i) {
- if (future.isPaused())
- future.waitForResume();
-
- if (future.isCanceled())
- break;
-
- const QString &fileName = files.at(i);
- future.setProgressValueAndText(i, QFileInfo(fileName).fileName());
-
- if (Document::Ptr previousDoc = snapshot.value(fileName)) {
- Control *control = previousDoc->control();
- const Identifier *id = control->findIdentifier(symbolId->chars(), symbolId->size());
- if (! id)
- continue; // skip this document, it's not using symbolId.
- }
-
- QByteArray source;
+ MyProcess process(wl, snapshot, symbol);
+ MyReduce reduce(&future);
- if (wl.contains(fileName))
- source = snapshot.preprocessedCode(wl.value(fileName), fileName);
- else {
- QFile file(fileName);
- if (! file.open(QFile::ReadOnly))
- continue;
-
- const QString contents = QTextStream(&file).readAll(); // ### FIXME
- source = snapshot.preprocessedCode(contents, fileName);
- }
-
- Document::Ptr doc = snapshot.documentFromSource(source, fileName);
- doc->tokenize();
-
- Control *control = doc->control();
- if (control->findIdentifier(symbolId->chars(), symbolId->size()) != 0) {
- doc->check();
-
- FindUsages process(doc, snapshot, &future);
- process.setGlobalNamespaceBinding(bind(doc, snapshot));
-
- process(symbol);
- }
- }
+ QtConcurrent::blockingMappedReduced<QList<Usage> > (files, process, reduce);
future.setProgressValue(files.size());
}