diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 07529dfe836..2662840340a 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"); @@ -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 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 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 0104406002e..2cc792006c6 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 declDefLink() const; void applyDeclDefLinkChanges(bool jumpToMatch); - QSharedPointer symbolFinder() const; - Q_SIGNALS: void outlineModelIndexChanged(const QModelIndex &index); @@ -336,7 +333,6 @@ private: QSharedPointer m_declDefLink; CppTools::CommentsSettings m_commentsSettings; - QSharedPointer m_symbolFinder; }; diff --git a/src/plugins/cppeditor/cppelementevaluator.cpp b/src/plugins/cppeditor/cppelementevaluator.cpp index 76dc4ec6eb2..5054da9d69f 100644 --- a/src/plugins/cppeditor/cppelementevaluator.cpp +++ b/src/plugins/cppeditor/cppelementevaluator.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -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 faae0669509..85f78aa85a0 100644 --- a/src/plugins/cppeditor/cppelementevaluator.h +++ b/src/plugins/cppeditor/cppelementevaluator.h @@ -36,7 +36,7 @@ #include "cppeditor.h" #include - +#include #include #include @@ -92,6 +92,7 @@ private: bool m_lookupDerivedClasses; QSharedPointer 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 ffcbb27d9ff..883f18d4fe2 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);