MCPcopy Create free account
hub / github.com/BaseXdb/basex / optimize

Method optimize

basex-core/src/main/java/org/basex/query/expr/Calc.java:52–74  ·  view source on GitHub ↗
(final Expr expr1, final Expr expr2, final InputInfo info,
        final CompileContext cc)

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 11

numTypeMethod · 0.95
seqTypeMethod · 0.95
getMethod · 0.95
getMethod · 0.95
oneOfMethod · 0.95
isMethod · 0.65
dblMethod · 0.45
equalsMethod · 0.45
itrMethod · 0.45
functionMethod · 0.45
argMethod · 0.45

Tested by

no test coverage detected