summaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@me.com>2013-02-26 11:11:43 +0100
committerErik Verbruggen <erik.verbruggen@digia.com>2013-02-26 14:54:47 +0100
commit2d3d53a0110711c3ab51020d2df647ffc4046bea (patch)
treeb568ad64dfbb02cf202824b0dc3f3699ea6899b2 /src/plugins
parent4d7e1c43db29bbcd1ea81b81e9bc140f2821def0 (diff)
downloadqt-creator-2d3d53a0110711c3ab51020d2df647ffc4046bea.tar.gz
C++: Fix/tune semantic highlighter result chunk size.
The fix: when finished with a FunctionDefinition, only flush when the number of usages reaches the chunk size. This should prevent a lot of chunks with a low number of usages for files with short methods. The tuning: for files larger than 10000 lines, use a larger chunk size to prevent the UI thread from having to re-layout/re-paint too often. Change-Id: I419174d306b8380c6fa8402825767e26c73f62ec Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/cpptools/cppchecksymbols.cpp17
-rw-r--r--src/plugins/cpptools/cppchecksymbols.h1
2 files changed, 13 insertions, 5 deletions
diff --git a/src/plugins/cpptools/cppchecksymbols.cpp b/src/plugins/cpptools/cppchecksymbols.cpp
index c6283ed2e4..d99e49934d 100644
--- a/src/plugins/cpptools/cppchecksymbols.cpp
+++ b/src/plugins/cpptools/cppchecksymbols.cpp
@@ -323,6 +323,13 @@ CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, cons
_potentialFunctions = collectTypes.functions();
_potentialStatics = collectTypes.statics();
+ unsigned line = 0;
+ getTokenEndPosition(translationUnit()->ast()->lastToken(), &line, 0);
+ _chunkSize = qMin(50U, line / 200);
+ _usages.reserve(_chunkSize);
+
+ _astStack.reserve(200);
+
typeOfExpression.init(_doc, _context.snapshot(), _context.bindings());
// make possible to instantiate templates
typeOfExpression.setExpandTemplates(true);
@@ -1055,7 +1062,8 @@ bool CheckSymbols::visit(FunctionDefinitionAST *ast)
}
if (!enclosingFunctionDefinition(true))
- flush();
+ if (_usages.size() >= _chunkSize)
+ flush();
return false;
}
@@ -1100,15 +1108,13 @@ void CheckSymbols::addUse(unsigned tokenIndex, UseKind kind)
addUse(use);
}
-static const int chunkSize = 50;
-
void CheckSymbols::addUse(const Use &use)
{
if (use.isInvalid())
return;
if (! enclosingFunctionDefinition()) {
- if (_usages.size() >= chunkSize) {
+ if (_usages.size() >= _chunkSize) {
if (use.line > _lineOfLastUsage)
flush();
}
@@ -1386,6 +1392,7 @@ void CheckSymbols::flush()
qSort(_usages.begin(), _usages.end(), sortByLinePredicate);
reportResults(_usages);
+ int cap = _usages.capacity();
_usages.clear();
- _usages.reserve(chunkSize);
+ _usages.reserve(cap);
}
diff --git a/src/plugins/cpptools/cppchecksymbols.h b/src/plugins/cpptools/cppchecksymbols.h
index 8b1694aed2..2b69e00081 100644
--- a/src/plugins/cpptools/cppchecksymbols.h
+++ b/src/plugins/cpptools/cppchecksymbols.h
@@ -175,6 +175,7 @@ private:
QSet<QByteArray> _potentialStatics;
QList<AST *> _astStack;
QVector<Use> _usages;
+ int _chunkSize;
unsigned _lineOfLastUsage;
QList<Use> _macroUses;
};