Tries to rewrite comparisons with empty strings. @param op operator @param cc compilation context @return optimized or original expression @throws QueryException query exception
(final CmpOp op, final CompileContext cc)
| 345 | * @throws QueryException query exception |
| 346 | */ |
| 347 | private Expr optEmptyString(final CmpOp op, final CompileContext cc) throws QueryException { |
| 348 | final Expr expr1 = exprs[0], expr2 = exprs[1]; |
| 349 | final SeqType st1 = expr1.seqType(); |
| 350 | if(st1.one() && st1.type.isStringOrUntyped() && expr2 == Str.EMPTY) { |
| 351 | if(op == CmpOp.LT) return Bln.FALSE; |
| 352 | if(op == CmpOp.GE) return Bln.TRUE; |
| 353 | // do not rewrite GT, as it may be rewritten to a range expression later on |
| 354 | if(op != CmpOp.GT) { |
| 355 | // EQ and LE can be treated identically |
| 356 | final Function func = op == CmpOp.NE ? BOOLEAN : NOT; |
| 357 | return cc.function(func, info, cc.function(DATA, info, exprs[0])); |
| 358 | } |
| 359 | } |
| 360 | return this; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Positional optimizations. |
no test coverage detected