Skip to content
Snippets Groups Projects
Commit 75bcf2bc authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Speedup global completion.

Don't sort the global completion items when we have too many of them, instead
populate the completion box in a way where local symbols are showed before
global symbols.
parent 64e9f652
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,10 @@ namespace { ...@@ -82,6 +82,10 @@ namespace {
const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty(); const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty();
} }
enum {
MAX_COMPLETION_ITEM = 1000
};
using namespace CPlusPlus; using namespace CPlusPlus;
namespace CppTools { namespace CppTools {
...@@ -654,8 +658,10 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor) ...@@ -654,8 +658,10 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
{ {
int index = startCompletionHelper(editor); int index = startCompletionHelper(editor);
if (index != -1) if (index != -1) {
if (m_completionOperator != T_EOF_SYMBOL)
qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan); qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
}
return index; return index;
} }
...@@ -891,9 +897,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope) ...@@ -891,9 +897,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
return; return;
} }
addKeywords();
addMacros(context.thisDocument()->fileName(), context.snapshot());
QList<ClassOrNamespace *> usingBindings; QList<ClassOrNamespace *> usingBindings;
ClassOrNamespace *currentBinding = 0; ClassOrNamespace *currentBinding = 0;
...@@ -916,20 +919,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope) ...@@ -916,20 +919,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
} }
} }
for (; currentBinding; currentBinding = currentBinding->parent()) {
const QList<Symbol *> symbols = currentBinding->symbols();
if (! symbols.isEmpty()) {
if (symbols.first()->isNamespace())
completeNamespace(currentBinding);
else
completeClass(currentBinding, false);
}
}
foreach (ClassOrNamespace *b, usingBindings)
completeNamespace(b);
for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) { for (Scope *scope = currentScope; scope; scope = scope->enclosingScope()) {
if (scope->isBlockScope()) { if (scope->isBlockScope()) {
for (unsigned i = 0; i < scope->symbolCount(); ++i) { for (unsigned i = 0; i < scope->symbolCount(); ++i) {
...@@ -945,6 +934,23 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope) ...@@ -945,6 +934,23 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
break; break;
} }
} }
for (; currentBinding; currentBinding = currentBinding->parent()) {
const QList<Symbol *> symbols = currentBinding->symbols();
if (! symbols.isEmpty()) {
if (symbols.first()->isNamespace())
completeNamespace(currentBinding);
else
completeClass(currentBinding, false);
}
}
foreach (ClassOrNamespace *b, usingBindings)
completeNamespace(b);
addKeywords();
addMacros(context.thisDocument()->fileName(), context.snapshot());
} }
bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results, bool CppCodeCompletion::completeConstructorOrFunction(const QList<LookupItem> &results,
...@@ -1590,6 +1596,10 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions() ...@@ -1590,6 +1596,10 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
completions(&completionItems); completions(&completionItems);
if (m_completionOperator == T_EOF_SYMBOL && completionItems.size() < MAX_COMPLETION_ITEM) {
qStableSort(completionItems.begin(), completionItems.end(), completionItemLessThan);
}
// Remove duplicates // Remove duplicates
QString lastKey; QString lastKey;
QList<TextEditor::CompletionItem> uniquelist; QList<TextEditor::CompletionItem> uniquelist;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment