[poincare] Multiplication::shallowReduce: simplify implementation!

(recursivelyMatches all children is equivalent to recursivelyMatches on
the current node)
This commit is contained in:
Émilie Feral
2020-02-03 17:25:55 +01:00
committed by Léa Saviot
parent ff438cbea8
commit 1484dbc5d4

View File

@@ -766,13 +766,7 @@ Expression Multiplication::privateShallowReduce(ExpressionNode::ReductionContext
const Expression c = childAtIndex(0);
if (c.type() == ExpressionNode::Type::Rational && static_cast<const Rational &>(c).isZero()) {
// Check that other children don't match inf or unit
bool infiniteOrUnitFactor = false;
for (int i = 1; i < numberOfChildren(); i++) {
infiniteOrUnitFactor = childAtIndex(i).recursivelyMatches([](const Expression e, Context * context) { return Expression::IsInfinity(e,context) || e.type() == ExpressionNode::Type::Unit; }, reductionContext.context());
if (infiniteOrUnitFactor) {
break;
}
}
bool infiniteOrUnitFactor = recursivelyMatches([](const Expression e, Context * context) { return Expression::IsInfinity(e,context) || e.type() == ExpressionNode::Type::Unit; }, reductionContext.context());
if (!infiniteOrUnitFactor) {
replaceWithInPlace(c);
return c;