From 28a625abd86a4ef253ee3bfc291f93d6027f0391 Mon Sep 17 00:00:00 2001 From: Alexander Mai Date: Sat, 19 Dec 2015 20:36:30 +0100 Subject: [PATCH] #7218 Improve performance in TokenList::validateAst(): Keep a list of 'verified' tokens during recursion check. --- lib/tokenlist.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index dc9b6c99f..22837596f 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1061,6 +1061,7 @@ void TokenList::createAst() void TokenList::validateAst() { + std::set < const Token* > astTokens; // Verify that ast looks ok for (const Token *tok = _front; tok; tok = tok->next()) { // Syntax error if binary operator only has 1 operand @@ -1076,6 +1077,10 @@ void TokenList::validateAst() while ((parent = parent->astParent()) != nullptr) { if (parent==tok) throw InternalError(tok, "AST broken: endless recursion from '" + tok->str() + "'", InternalError::SYNTAX); + if (astTokens.find(parent)!= astTokens.end()) { + break; + } + astTokens.insert(parent); } } }