forked from qt-creator/qt-creator
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>
This commit is contained in:
committed by
Erik Verbruggen
parent
4d7e1c43db
commit
2d3d53a011
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user