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

Method optEmptyString

basex-core/src/main/java/org/basex/query/expr/Cmp.java:347–361  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 1

optMethod · 0.95

Calls 4

seqTypeMethod · 0.95
oneMethod · 0.95
isStringOrUntypedMethod · 0.65
functionMethod · 0.45

Tested by

no test coverage detected