From 7750c4ec459469ec9a3781c22b0e0a2f6e4b2cf0 Mon Sep 17 00:00:00 2001 From: Karol Stasiak Date: Tue, 7 Aug 2018 17:36:14 +0200 Subject: [PATCH] Optimize constants of form (B+A)-B --- src/main/scala/millfork/env/Constant.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/scala/millfork/env/Constant.scala b/src/main/scala/millfork/env/Constant.scala index a5097b0b..eaa6d5f1 100644 --- a/src/main/scala/millfork/env/Constant.scala +++ b/src/main/scala/millfork/env/Constant.scala @@ -263,6 +263,8 @@ case class CompoundConstant(operator: MathOperator.Value, lhs: Constant, rhs: Co } else { CompoundConstant(MathOperator.Minus, a, rr - ll).quickSimplify } + case (CompoundConstant(MathOperator.Plus, a, ll@NumericConstant(lv, _)), b) if operator == MathOperator.Minus && a == b => + ll.quickSimplify case (CompoundConstant(MathOperator.Minus, a, ll@NumericConstant(lv, _)), rr@NumericConstant(rv, _)) if operator == MathOperator.Plus => if (lv >= rv) { CompoundConstant(MathOperator.Minus, a, ll - rr).quickSimplify