diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-09-06 16:46:23 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-09-06 16:53:46 +0200 |
commit | 86799309aaa491076e68d257640903d6e0c719e5 (patch) | |
tree | de7512d3e8a4d5e9a3917b20c6ce257d58c39deb /src/plugins | |
parent | 6863b02e034a096e6d0441ecf1f54558953c358f (diff) | |
download | qt-creator-86799309aaa491076e68d257640903d6e0c719e5.tar.gz |
Keep the locator database in sync with the current snapshot.
Thanks to this patch we can move the filtering of C++ symbols
in a background thread.
Done-with: Erik Verbruggen
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 9 | ||||
-rw-r--r-- | src/plugins/cpptools/cpplocatorfilter.cpp | 16 | ||||
-rw-r--r-- | src/plugins/cpptools/cpplocatorfilter.h | 12 | ||||
-rw-r--r-- | src/plugins/cpptools/searchsymbols.cpp | 10 | ||||
-rw-r--r-- | src/plugins/cpptools/searchsymbols.h | 18 | ||||
-rw-r--r-- | src/plugins/locator/locatorwidget.cpp | 2 |
6 files changed, 33 insertions, 34 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index c13b3da5f1..40294cde5e 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -375,6 +375,9 @@ struct CanonicalSymbol }; + +int numberOfClosedEditors = 0; + } // end of anonymous namespace CPPEditorEditable::CPPEditorEditable(CPPEditor *editor) @@ -428,6 +431,12 @@ CPPEditor::~CPPEditor() m_semanticHighlighter->abort(); m_semanticHighlighter->wait(); + + ++numberOfClosedEditors; + if (numberOfClosedEditors == 5) { + m_modelManager->GC(); + numberOfClosedEditors = 0; + } } TextEditor::BaseTextEditorEditable *CPPEditor::createEditableInterface() diff --git a/src/plugins/cpptools/cpplocatorfilter.cpp b/src/plugins/cpptools/cpplocatorfilter.cpp index 34c696a15d..2b10afdce6 100644 --- a/src/plugins/cpptools/cpplocatorfilter.cpp +++ b/src/plugins/cpptools/cpplocatorfilter.cpp @@ -56,7 +56,7 @@ CppLocatorFilter::~CppLocatorFilter() void CppLocatorFilter::onDocumentUpdated(CPlusPlus::Document::Ptr doc) { - m_searchList[doc->fileName()] = Info(doc); + m_searchList[doc->fileName()] = search(doc); } void CppLocatorFilter::onAboutToRemoveFiles(const QStringList &files) @@ -88,20 +88,12 @@ QList<Locator::FilterEntry> CppLocatorFilter::matchesFor(const QString &origEntr return goodEntries; bool hasWildcard = (entry.contains(asterisk) || entry.contains('?')); - QMutableMapIterator<QString, Info> it(m_searchList); + QHashIterator<QString, QList<ModelItemInfo> > it(m_searchList); while (it.hasNext()) { it.next(); - Info info = it.value(); - if (info.dirty) { - info.dirty = false; - info.items = search(info.doc); - it.setValue(info); - } - - QList<ModelItemInfo> items = info.items; - - foreach (ModelItemInfo info, items) { + const QList<ModelItemInfo> items = it.value(); + foreach (const ModelItemInfo &info, items) { if ((hasWildcard && regexp.exactMatch(info.symbolName)) || (!hasWildcard && matcher.indexIn(info.symbolName) != -1)) { diff --git a/src/plugins/cpptools/cpplocatorfilter.h b/src/plugins/cpptools/cpplocatorfilter.h index 4c4df83a23..7b13adc6c7 100644 --- a/src/plugins/cpptools/cpplocatorfilter.h +++ b/src/plugins/cpptools/cpplocatorfilter.h @@ -31,7 +31,6 @@ #define CPPLOCATORFILTER_H #include "searchsymbols.h" - #include <locator/ilocatorfilter.h> namespace CppTools { @@ -63,16 +62,7 @@ private slots: private: CppModelManager *m_manager; - struct Info { - Info(): dirty(true) {} - Info(CPlusPlus::Document::Ptr doc): doc(doc), dirty(true) {} - - CPlusPlus::Document::Ptr doc; - QList<ModelItemInfo> items; - bool dirty; - }; - - QMap<QString, Info> m_searchList; + QHash<QString, QList<ModelItemInfo> > m_searchList; QList<ModelItemInfo> m_previousResults; bool m_forceNewSearchList; QString m_previousEntry; diff --git a/src/plugins/cpptools/searchsymbols.cpp b/src/plugins/cpptools/searchsymbols.cpp index 828f0ce2ef..01aecaa236 100644 --- a/src/plugins/cpptools/searchsymbols.cpp +++ b/src/plugins/cpptools/searchsymbols.cpp @@ -67,6 +67,7 @@ QList<ModelItemInfo> SearchSymbols::operator()(Document::Ptr doc, const QString accept(doc->globalSymbolAt(i)); } (void) switchScope(previousScope); + strings.clear(); return items; } @@ -216,10 +217,17 @@ void SearchSymbols::appendItem(const QString &name, QStringList fullyQualifiedName; foreach (const Name *name, LookupContext::fullyQualifiedName(symbol)) fullyQualifiedName.append(overview.prettyName(name)); + + QString path = m_paths.value(symbol->fileId(), QString()); + if (path.isEmpty()) { + path = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()); + m_paths.insert(symbol->fileId(), path); + } + const QIcon icon = icons.iconForSymbol(symbol); items.append(ModelItemInfo(name, info, type, fullyQualifiedName, - QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()), + path, symbol->line(), symbol->column() - 1, // 1-based vs 0-based column icon)); diff --git a/src/plugins/cpptools/searchsymbols.h b/src/plugins/cpptools/searchsymbols.h index 9a08b4dced..5b61fe783b 100644 --- a/src/plugins/cpptools/searchsymbols.h +++ b/src/plugins/cpptools/searchsymbols.h @@ -40,6 +40,7 @@ #include <QMetaType> #include <QString> #include <QSet> +#include <QHash> #include <functional> @@ -66,33 +67,33 @@ struct ModelItemInfo const QIcon &icon) : symbolName(symbolName), symbolType(symbolType), - type(type), fullyQualifiedName(fullyQualifiedName), fileName(fileName), + icon(icon), + type(type), line(line), - column(column), - icon(icon) + column(column) { } ModelItemInfo(const ModelItemInfo &otherInfo) : symbolName(otherInfo.symbolName), symbolType(otherInfo.symbolType), - type(otherInfo.type), fullyQualifiedName(otherInfo.fullyQualifiedName), fileName(otherInfo.fileName), + icon(otherInfo.icon), + type(otherInfo.type), line(otherInfo.line), - column(otherInfo.column), - icon(otherInfo.icon) + column(otherInfo.column) { } QString symbolName; QString symbolType; - ItemType type; QStringList fullyQualifiedName; QString fileName; + QIcon icon; + ItemType type; int line; int column; - QIcon icon; }; class SearchSymbols: public std::unary_function<CPlusPlus::Document::Ptr, QList<ModelItemInfo> >, @@ -152,6 +153,7 @@ private: CPlusPlus::Icons icons; QList<ModelItemInfo> items; SymbolTypes symbolsToSearchFor; + QHash<const CPlusPlus::StringLiteral *, QString> m_paths; bool separateScope; }; diff --git a/src/plugins/locator/locatorwidget.cpp b/src/plugins/locator/locatorwidget.cpp index 8f29bbba7a..0ee99048ea 100644 --- a/src/plugins/locator/locatorwidget.cpp +++ b/src/plugins/locator/locatorwidget.cpp @@ -439,7 +439,6 @@ static void filter_helper(QFutureInterface<FilterEntry> &entries, QList<ILocator foreach (const FilterEntry &entry, filter->matchesFor(searchText)) { if (checkDuplicates && alreadyAdded.contains(entry)) continue; - //entries.append(entry); entries.reportResult(entry); if (checkDuplicates) alreadyAdded.insert(entry); @@ -457,7 +456,6 @@ void LocatorWidget::updateCompletionList(const QString &text) QFuture<FilterEntry> future = QtConcurrent::run(filter_helper, filters, searchText); m_entriesWatcher->setFuture(future); - future.waitForFinished(); } void LocatorWidget::updateEntries() |