| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public Expr optimize(final Expr expr1, final Expr expr2, final InputInfo info, |
| 54 | final CompileContext cc) throws QueryException { |
| 55 | // check for neutral number |
| 56 | final Type type = numType(expr1.seqType().type, expr2.seqType().type); |
| 57 | if(expr2 instanceof final ANum num && num.dbl() == 0) { |
| 58 | return new Cast(info, expr1, type.seqType()).optimize(cc); |
| 59 | } |
| 60 | // merge arithmetical expressions |
| 61 | if(expr1.equals(expr2)) { |
| 62 | return new Arith(info, expr1, Itr.get(2), MULTIPLY).optimize(cc); |
| 63 | } |
| 64 | if(expr2 instanceof final Unary unry) { |
| 65 | return new Arith(info, expr1, unry.expr, SUBTRACT).optimize(cc); |
| 66 | } |
| 67 | if(expr1 instanceof final Arith arth) { |
| 68 | if(arth.calc == MULTIPLY && arth.exprs[0].equals(expr2) && |
| 69 | arth.exprs[1] instanceof final Itr itr) { |
| 70 | return new Arith(info, arth.exprs[0], Itr.get(itr.itr() + 1), MULTIPLY).optimize(cc); |
| 71 | } |
| 72 | } |
| 73 | return null; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public Type type(final Type type1, final Type type2) { |