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

Method optimize

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

Source from the content-addressed store, hash-verified

65 }
66
67 @Override
68 public Expr optimize(final CompileContext cc) throws QueryException {
69 if(EMPTY.is(cond)) {
70 // if(empty(A)) then B else C → if(exists(A)) then C else B
71 cond = cc.function(EXISTS, cond.info(info), cond.arg(0));
72 swap();
73 cc.info(QueryText.OPTSWAP_X, this);
74 } else if(NOT.is(cond)) {
75 // if(not(A)) then B else C → if(A) then C else B
76 cond = cond.arg(0);
77 swap();
78 cc.info(QueryText.OPTSWAP_X, this);
79 }
80 // if(exists($nodes)) → if($nodes)
81 cond = cond.simplifyFor(Simplify.EBV, cc);
82
83 return cc.replaceWith(this, opt(cc));
84 }
85
86 /**
87 * Optimizes the expression.

Callers 15

compileMethod · 0.95
inlineMethod · 0.95
typeCheckMethod · 0.95
functionMethod · 0.45
copyMethod · 0.45
optMethod · 0.45
simplifyForMethod · 0.45
optBooleanMethod · 0.45
compileMethod · 0.45
inlineMethod · 0.45
compileMethod · 0.45
compileMethod · 0.45

Calls 8

swapMethod · 0.95
optMethod · 0.95
replaceWithMethod · 0.80
isMethod · 0.65
infoMethod · 0.65
functionMethod · 0.45
argMethod · 0.45
simplifyForMethod · 0.45

Tested by

no test coverage detected