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

Method optimize

basex-core/src/main/java/org/basex/query/expr/Range.java:39–67  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

37 }
38
39 @Override
40 public Expr optimize(final CompileContext cc) throws QueryException {
41 exprs = simplifyAll(Simplify.NUMBER, cc);
42
43 Expr expr = emptyExpr();
44 if(expr == this) {
45 if(values(false, cc)) return cc.preEval(this);
46
47 final Expr min = exprs[0], max = exprs[1];
48 if(!min.has(Flag.NDT)) {
49 if(min.equals(max)) {
50 // identical operands: $int to $int
51 exprType.assign(Occ.EXACTLY_ONE);
52 if(integers()) expr = min;
53 } else if(max instanceof final Arith arith && min.equals(max.arg(0))) {
54 if(arith.calc.oneOf(Calc.ADD, Calc.SUBTRACT) && arith.arg(1) instanceof final Itr itr) {
55 // known result size: . to . + 10
56 final long n = (arith.calc == Calc.ADD ? itr.itr() : -itr.itr()) + 1;
57 if(n < 1) {
58 expr = Empty.VALUE;
59 } else {
60 exprType.assign(seqType(), n);
61 }
62 }
63 }
64 }
65 }
66 return cc.replaceWith(this, expr);
67 }
68
69 /**
70 * Indicates if the range operands are known to return single integers.

Callers 1

optimizePosMethod · 0.45

Calls 14

hasMethod · 0.95
equalsMethod · 0.95
integersMethod · 0.95
argMethod · 0.95
simplifyAllMethod · 0.80
emptyExprMethod · 0.80
replaceWithMethod · 0.80
oneOfMethod · 0.65
seqTypeMethod · 0.65
valuesMethod · 0.45
preEvalMethod · 0.45
assignMethod · 0.45

Tested by

no test coverage detected