Skip to content

Commit 02f9ab3

Browse files
committed
simplifyCalculations: Made this function ~30% faster when analysing lib/tokenize.cpp
1 parent 8d55d36 commit 02f9ab3

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

lib/templatesimplifier.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,10 +1235,6 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok)
12351235
ret = true;
12361236
}
12371237

1238-
if (Token::Match(tok, "%oror%|&& %num% %oror%|&&|,|)") || Token::Match(tok, "[(,] %num% %oror%|&&")) {
1239-
tok->next()->str(MathLib::isNullValue(tok->next()->str()) ? "0" : "1");
1240-
}
1241-
12421238
return ret;
12431239
}
12441240

@@ -1273,6 +1269,19 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
12731269
}
12741270

12751271
if (tok->isNumber()) {
1272+
if (simplifyNumericCalculations(tok->previous())) {
1273+
ret = true;
1274+
tok = tok->previous();
1275+
while (Token::Match(tok->tokAt(-2), "%cop%|,|( %num% %cop% %num% %cop%|,|)")) {
1276+
Token *before = tok->tokAt(-2);
1277+
if (simplifyNumericCalculations(before))
1278+
tok = before;
1279+
else
1280+
break;
1281+
}
1282+
tok = tok->next();
1283+
}
1284+
12761285
// Remove redundant conditions (0&&x) (1||x)
12771286
if (Token::Match(tok->previous(), "[(=,] 0 &&") ||
12781287
Token::Match(tok->previous(), "[(=,] 1 %oror%")) {
@@ -1408,17 +1417,6 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
14081417
}
14091418
}
14101419
}
1411-
1412-
else if (simplifyNumericCalculations(tok)) {
1413-
ret = true;
1414-
while (Token::Match(tok->tokAt(-2), "%cop%|,|( %num% %cop% %num% %cop%|,|)")) {
1415-
Token *before = tok->tokAt(-2);
1416-
if (simplifyNumericCalculations(before))
1417-
tok = before;
1418-
else
1419-
break;
1420-
}
1421-
}
14221420
}
14231421
return ret;
14241422
}

0 commit comments

Comments
 (0)