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

Method optimize

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

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 15

addMethod · 0.95
isEmptyMethod · 0.95
getMethod · 0.95
nextMethod · 0.95
finishMethod · 0.95
seqTypeMethod · 0.95
replaceWithMethod · 0.80
zeroOrOneMethod · 0.80
addMethod · 0.65
sizeMethod · 0.65
infoMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected