C++: Cache parsing of template ids

...in order to stop memory intensive parsing for invalid code.

Parsing the test data/snippet "hard" led to a memory consumption of
about 5.5MB and this could easily get up to hundreds/gigabytes by adding
some more "if_<bool_<true>,\n" lines. With the caching, we are at about
1.0MB, even if more lines are added.

The "memory consumption" was measured with valgrind-massif. The stated
numbers are the reported peaks.

Task-number: QTCREATORBUG-12890
Change-Id: Ie7eb00cfc7915552d29bb27410a6b13a486f486e
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2015-02-10 16:21:53 +01:00
parent ae3aa07c4d
commit 921ec6da5a
2 changed files with 66 additions and 7 deletions

View File

@@ -165,6 +165,7 @@ public:
Expression,
ExpressionList,
ParameterDeclarationClause,
TemplateId,
TypeId
};
@@ -510,6 +511,7 @@ bool Parser::parseClassOrNamespaceName(NameAST *&node)
bool Parser::parseTemplateId(NameAST *&node, unsigned template_token)
{
DEBUG_THIS_RULE();
CHECK_CACHE(ASTCache::TemplateId, NameAST);
const unsigned start = cursor();
@@ -523,14 +525,17 @@ bool Parser::parseTemplateId(NameAST *&node, unsigned template_token)
if (maybeSplitGreaterGreaterToken() || LA() == T_GREATER) {
ast->greater_token = consumeToken();
node = ast;
return true;
const bool result = true;
_astCache->insert(ASTCache::TemplateId, start, node, cursor(), result);
return result;
}
}
}
const bool result = false;
_astCache->insert(ASTCache::TemplateId, start, 0, cursor(), result);
rewind(start);
return false;
return result;
}
bool Parser::parseNestedNameSpecifier(NestedNameSpecifierListAST *&node,