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

Method optimize

basex-core/src/main/java/org/basex/query/expr/gflwor/For.java:121–145  ·  view source on GitHub ↗
(final CompileContext cc)

Source from the content-addressed store, hash-verified

119 }
120
121 @Override
122 public For optimize(final CompileContext cc) throws QueryException {
123 // for $a as xs:integer in $array → for $a as xs:integer in data($array)
124 final SeqType dt = var.declType;
125 if(dt != null && dt.instanceOf(Types.ANY_ATOMIC_TYPE_ZM) && expr.seqType().mayBeWrapped()) {
126 expr = cc.function(DATA, info, expr);
127 }
128
129 // remove empty flag if expression is never empty; assign type to clause and variable
130 final SeqType st = expr.seqType();
131 if(st.oneOrMore()) empty = false;
132 exprType.assign(st.with(empty ? st.zero() ? Occ.ZERO : Occ.ZERO_OR_ONE : Occ.EXACTLY_ONE));
133
134 var.refineType(seqType(), size(), cc);
135 var.expr(expr);
136 if(pos != null) {
137 pos.refineType(Types.INTEGER_O, 1, cc);
138 pos.expr(Itr.ZERO);
139 }
140 if(score != null) {
141 score.refineType(Types.DOUBLE_O, 1, cc);
142 score.expr(Dbl.ZERO);
143 }
144 return this;
145 }
146
147 @Override
148 public For copy(final CompileContext cc, final IntObjectMap<Var> vm) {

Callers 1

asLetMethod · 0.45

Calls 11

instanceOfMethod · 0.95
oneOrMoreMethod · 0.95
withMethod · 0.95
zeroMethod · 0.95
mayBeWrappedMethod · 0.80
seqTypeMethod · 0.65
sizeMethod · 0.65
functionMethod · 0.45
assignMethod · 0.45
refineTypeMethod · 0.45
exprMethod · 0.45

Tested by

no test coverage detected