(final CompileContext cc)
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Expr optimize(final CompileContext cc) throws QueryException { |
| 55 | // merge adjacent values, ignore empty sequences |
| 56 | final int el = exprs.length; |
| 57 | final ExprList list = new ExprList(el); |
| 58 | final TokenBuilder tb = new TokenBuilder(); |
| 59 | for(final Expr expr : exprs) { |
| 60 | if(cc.values(true, expr)) { |
| 61 | for(final Item item : expr.atomValue(cc.qc, info)) { |
| 62 | tb.add(item.string(info)); |
| 63 | } |
| 64 | } else { |
| 65 | if(!tb.isEmpty()) list.add(Str.get(tb.next())); |
| 66 | list.add(expr); |
| 67 | } |
| 68 | } |
| 69 | if(list.isEmpty()) return cc.replaceWith(this, Str.get(tb.finish())); |
| 70 | if(!tb.isEmpty()) list.add(Str.get(tb.finish())); |
| 71 | |
| 72 | // single expression left: replace with string call |
| 73 | final int ls = list.size(); |
| 74 | if(ls == 1) { |
| 75 | final Expr arg = list.peek(); |
| 76 | if(arg.seqType().zeroOrOne()) { |
| 77 | return cc.replaceWith(this, cc.function(Function.STRING, info, arg)); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // replace old with new expressions |
| 82 | if(ls != el) cc.info(QueryText.OPTMERGE_X, this); |
| 83 | exprs = list.finish(); |
| 84 | return this; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean equals(final Object obj) { |
nothing calls this directly
no test coverage detected