Commit 2d3d53a0 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Erik Verbruggen

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: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 4d7e1c43
......@@ -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);
}
......@@ -175,6 +175,7 @@ private:
QSet<QByteArray> _potentialStatics;
QList<AST *> _astStack;
QVector<Use> _usages;
int _chunkSize;
unsigned _lineOfLastUsage;
QList<Use> _macroUses;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment