summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodecompletion.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2010-05-27 19:00:44 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2010-05-27 19:00:44 +0200
commit75bcf2bc663b754b795992846a1db92f99480db4 (patch)
tree32a459e2246e194a88fded02bfa68161595552d2 /src/plugins/cpptools/cppcodecompletion.cpp
parent64e9f652e07883c8c9c081a4b179bbbd6444b67f (diff)
downloadqt-creator-75bcf2bc663b754b795992846a1db92f99480db4.tar.gz
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.
Diffstat (limited to 'src/plugins/cpptools/cppcodecompletion.cpp')
-rw-r--r--src/plugins/cpptools/cppcodecompletion.cpp48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/plugins/cpptools/cppcodecompletion.cpp b/src/plugins/cpptools/cppcodecompletion.cpp
index afd2b7b77d..f9aeb71056 100644
--- a/src/plugins/cpptools/cppcodecompletion.cpp
+++ b/src/plugins/cpptools/cppcodecompletion.cpp
@@ -82,6 +82,10 @@ namespace {
const bool debug = ! qgetenv("CPLUSPLUS_DEBUG").isEmpty();
}
+enum {
+ MAX_COMPLETION_ITEM = 1000
+};
+
using namespace CPlusPlus;
namespace CppTools {
@@ -654,8 +658,10 @@ bool CppCodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
{
int index = startCompletionHelper(editor);
- if (index != -1)
- qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
+ if (index != -1) {
+ if (m_completionOperator != T_EOF_SYMBOL)
+ qStableSort(m_completions.begin(), m_completions.end(), completionItemLessThan);
+ }
return index;
}
@@ -891,9 +897,6 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
return;
}
- addKeywords();
- addMacros(context.thisDocument()->fileName(), context.snapshot());
-
QList<ClassOrNamespace *> usingBindings;
ClassOrNamespace *currentBinding = 0;
@@ -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()) {
if (scope->isBlockScope()) {
for (unsigned i = 0; i < scope->symbolCount(); ++i) {
@@ -945,6 +934,23 @@ void CppCodeCompletion::globalCompletion(Scope *currentScope)
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,
@@ -1590,6 +1596,10 @@ QList<TextEditor::CompletionItem> CppCodeCompletion::getCompletions()
completions(&completionItems);
+ if (m_completionOperator == T_EOF_SYMBOL && completionItems.size() < MAX_COMPLETION_ITEM) {
+ qStableSort(completionItems.begin(), completionItems.end(), completionItemLessThan);
+ }
+
// Remove duplicates
QString lastKey;
QList<TextEditor::CompletionItem> uniquelist;