(final CompileContext cc)
| 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. |
no test coverage detected