simplifyCalculations: Made this function ~30% faster when analysing lib/tokenize.cpp
This commit is contained in:
parent
8d55d361ae
commit
02f9ab38b4
|
@ -1235,10 +1235,6 @@ bool TemplateSimplifier::simplifyNumericCalculations(Token *tok)
|
||||||
ret = true;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1273,6 +1269,19 @@ bool TemplateSimplifier::simplifyCalculations(Token *_tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tok->isNumber()) {
|
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)
|
// Remove redundant conditions (0&&x) (1||x)
|
||||||
if (Token::Match(tok->previous(), "[(=,] 0 &&") ||
|
if (Token::Match(tok->previous(), "[(=,] 0 &&") ||
|
||||||
Token::Match(tok->previous(), "[(=,] 1 %oror%")) {
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue