simplifyCalculations: Made this function ~30% faster when analysing lib/tokenize.cpp

This commit is contained in:
Daniel Marjamäki 2018-05-31 06:36:59 +02:00
parent 8d55d361ae
commit 02f9ab38b4
1 changed files with 13 additions and 15 deletions

View File

@ -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;
}