diff options
author | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-02-10 16:21:53 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@theqtcompany.com> | 2015-02-12 10:40:14 +0000 |
commit | 921ec6da5af9e412e8fd582e10c2ffa9830b1dd5 (patch) | |
tree | b9bf625213328e1c2de1d782115cb5f1fcebfade /src/libs/3rdparty/cplusplus/Parser.cpp | |
parent | ae3aa07c4df1f8e6e413b7513611d306063b126b (diff) |
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>
Diffstat (limited to 'src/libs/3rdparty/cplusplus/Parser.cpp')
-rw-r--r-- | src/libs/3rdparty/cplusplus/Parser.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/libs/3rdparty/cplusplus/Parser.cpp b/src/libs/3rdparty/cplusplus/Parser.cpp index 86eeaa2f2a..75970b1671 100644 --- a/src/libs/3rdparty/cplusplus/Parser.cpp +++ b/src/libs/3rdparty/cplusplus/Parser.cpp @@ -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, |