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