From 02f9ab38b4b2e4f106ce8a55fa33d3f3b7279b20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 31 May 2018 06:36:59 +0200 Subject: [PATCH] simplifyCalculations: Made this function ~30% faster when analysing lib/tokenize.cpp --- lib/templatesimplifier.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 3a11cffe0..73f4ff9e2 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1235,10 +1235,6 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok) ret = true; } - if (Token::Match(tok, "%oror%|&& %num% %oror%|&&|,|)") || Token::Match(tok, "[(,] %num% %oror%|&&")) { - tok->next()->str(MathLib::isNullValue(tok->next()->str()) ? "0" : "1"); - } - return ret; } @@ -1273,6 +1269,19 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) } if (tok->isNumber()) { + if (simplifyNumericCalculations(tok->previous())) { + ret = true; + tok = tok->previous(); + while (Token::Match(tok->tokAt(-2), "%cop%|,|( %num% %cop% %num% %cop%|,|)")) { + Token *before = tok->tokAt(-2); + if (simplifyNumericCalculations(before)) + tok = before; + else + break; + } + tok = tok->next(); + } + // Remove redundant conditions (0&&x) (1||x) if (Token::Match(tok->previous(), "[(=,] 0 &&") || Token::Match(tok->previous(), "[(=,] 1 %oror%")) { @@ -1408,17 +1417,6 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens) } } } - - else if (simplifyNumericCalculations(tok)) { - ret = true; - while (Token::Match(tok->tokAt(-2), "%cop%|,|( %num% %cop% %num% %cop%|,|)")) { - Token *before = tok->tokAt(-2); - if (simplifyNumericCalculations(before)) - tok = before; - else - break; - } - } } return ret; }