diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 07529dfe836d786603ed93e8779954f469b0e162..2662840340a6b941e7cbcd0622dcca7d1d628275 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -412,6 +412,8 @@ CPPEditor::CPPEditor(CPPEditorWidget *editor) m_context.add(TextEditor::Constants::C_TEXTEDITOR); } +Q_GLOBAL_STATIC(CppTools::SymbolFinder, symbolFinder) + CPPEditorWidget::CPPEditorWidget(QWidget *parent) : TextEditor::BaseTextEditorWidget(parent) , m_currentRenameSelection(NoCurrentRenameSelection) @@ -420,7 +422,6 @@ CPPEditorWidget::CPPEditorWidget(QWidget *parent) , m_firstRenameChange(false) , m_objcEnabled(false) , m_commentsSettings(CppTools::CppToolsSettings::instance()->commentsSettings()) - , m_symbolFinder(new CppTools::SymbolFinder) { m_initialized = false; qRegisterMetaType<CppEditor::Internal::SemanticInfo>("CppEditor::Internal::SemanticInfo"); @@ -1078,7 +1079,7 @@ void CPPEditorWidget::switchDeclarationDefinition() openCppEditorAt(linkToSymbol(best.first())); } else if (lastVisibleSymbol && lastVisibleSymbol->isDeclaration() && lastVisibleSymbol->type()->isFunctionType()) { - if (Symbol *def = m_symbolFinder->findMatchingDefinition(lastVisibleSymbol, snapshot)) + if (Symbol *def = symbolFinder()->findMatchingDefinition(lastVisibleSymbol, snapshot)) openCppEditorAt(linkToSymbol(def)); } } @@ -1174,12 +1175,12 @@ CPPEditorWidget::Link CPPEditorWidget::attemptFuncDeclDef(const QTextCursor &cur Symbol *target = 0; if (FunctionDefinitionAST *funDef = declParent->asFunctionDefinition()) { QList<Declaration *> candidates = - m_symbolFinder->findMatchingDeclaration(LookupContext(doc, snapshot), + symbolFinder()->findMatchingDeclaration(LookupContext(doc, snapshot), funDef->symbol); if (!candidates.isEmpty()) // TODO: improve disambiguation target = candidates.first(); } else if (declParent->asSimpleDeclaration()) { - target = m_symbolFinder->findMatchingDefinition(funcDecl->symbol, snapshot); + target = symbolFinder()->findMatchingDefinition(funcDecl->symbol, snapshot); } if (target) { @@ -1430,7 +1431,7 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor, def = 0; // jump to declaration then. if (symbol->isForwardClassDeclaration()) - def = m_symbolFinder->findMatchingClassDeclaration(symbol, snapshot); + def = symbolFinder()->findMatchingClassDeclaration(symbol, snapshot); } link = linkToSymbol(def ? def : symbol); @@ -1466,7 +1467,7 @@ Symbol *CPPEditorWidget::findDefinition(Symbol *symbol, const Snapshot &snapshot else if (! symbol->type()->isFunctionType()) return 0; // not a function declaration - return m_symbolFinder->findMatchingDefinition(symbol, snapshot); + return symbolFinder()->findMatchingDefinition(symbol, snapshot); } unsigned CPPEditorWidget::editorRevision() const @@ -2256,11 +2257,6 @@ void CPPEditorWidget::applyDeclDefLinkChanges(bool jumpToMatch) updateFunctionDeclDefLink(); } -QSharedPointer<CppTools::SymbolFinder> CPPEditorWidget::symbolFinder() const -{ - return m_symbolFinder; -} - void CPPEditorWidget::abortDeclDefLink() { if (!m_declDefLink) diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 0104406002e9df4550f769399b6f8459e66e74dd..2cc792006c612a008520867ada4b12eed6be6437 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -65,7 +65,6 @@ class CppModelManagerInterface; namespace CppTools { class CppCodeStyleSettings; class CppRefactoringFile; -class SymbolFinder; } namespace TextEditor { @@ -201,8 +200,6 @@ public: QSharedPointer<FunctionDeclDefLink> declDefLink() const; void applyDeclDefLinkChanges(bool jumpToMatch); - QSharedPointer<CppTools::SymbolFinder> symbolFinder() const; - Q_SIGNALS: void outlineModelIndexChanged(const QModelIndex &index); @@ -336,7 +333,6 @@ private: QSharedPointer<FunctionDeclDefLink> m_declDefLink; CppTools::CommentsSettings m_commentsSettings; - QSharedPointer<CppTools::SymbolFinder> m_symbolFinder; }; diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index 76dc4ec6eb2af0f2ce53a2fae4455c1419a03425..5054da9d69fe7a9ce2554c498fddcfb994b323ae 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -34,7 +34,6 @@ #include <coreplugin/ifile.h> #include <cpptools/cpptoolsreuse.h> -#include <cpptools/symbolfinder.h> #include <FullySpecifiedType.h> #include <Literals.h> @@ -186,8 +185,7 @@ void CppElementEvaluator::handleLookupItemMatch(const Snapshot &snapshot, || declaration->asTemplate()->declaration()->isForwardClassDeclaration()))) { if (declaration->isForwardClassDeclaration()) if (Symbol *classDeclaration = - m_editor->symbolFinder()->findMatchingClassDeclaration( - declaration, snapshot)) { + m_symbolFinder.findMatchingClassDeclaration(declaration, snapshot)) { declaration = classDeclaration; } CppClass *cppClass = new CppClass(declaration); diff --git a/src/plugins/cppeditor/cppelementevaluator.h b/src/plugins/cppeditor/cppelementevaluator.h index faae06695091c4cef9521cf8f399b89acbde77fd..85f78aa85a02cfd96f44cd707d5fbeac04bed6eb 100644 --- a/src/plugins/cppeditor/cppelementevaluator.h +++ b/src/plugins/cppeditor/cppelementevaluator.h @@ -36,7 +36,7 @@ #include "cppeditor.h" #include <texteditor/helpitem.h> - +#include <cpptools/symbolfinder.h> #include <cplusplus/CppDocument.h> #include <cplusplus/Overview.h> @@ -92,6 +92,7 @@ private: bool m_lookupDerivedClasses; QSharedPointer<CppElement> m_element; QString m_diagnosis; + CppTools::SymbolFinder m_symbolFinder; }; class CppElement diff --git a/src/plugins/cpptools/symbolfinder.cpp b/src/plugins/cpptools/symbolfinder.cpp index ffcbb27d9ffe99ad3563e8c3a6b55518922cb76d..883f18d4fe2580fc9877b7ff3a269f21795f1475 100644 --- a/src/plugins/cpptools/symbolfinder.cpp +++ b/src/plugins/cpptools/symbolfinder.cpp @@ -65,7 +65,7 @@ public: } // end of anonymous namespace -static const int kMaxSize = 10; +static const int kMaxCacheSize = 10; SymbolFinder::SymbolFinder() {} @@ -339,7 +339,7 @@ void SymbolFinder::trackCacheUse(const QString &referenceFile) m_recent.append(referenceFile); // We don't want this to grow too much. - if (m_recent.size() > kMaxSize) { + if (m_recent.size() > kMaxCacheSize) { const QString &oldest = m_recent.takeFirst(); m_filePriorityCache.remove(oldest); m_fileMetaCache.remove(oldest);