We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 78041ec commit 29da3eaCopy full SHA for 29da3ea
basex-core/src/main/java/org/basex/query/func/fn/FnReverse.java
@@ -76,6 +76,8 @@ protected Expr opt(final CompileContext cc) throws QueryException {
76
// reverse sequence
77
if(expr instanceof RangeSeq) return ((RangeSeq) expr).reverse(cc.qc);
78
79
+ // reverse(reverse(E)) -> E
80
+ if(REVERSE.is(expr)) return expr.arg(0);
81
// reverse(tail(reverse(E)) -> util:init(E)
82
if(TAIL.is(expr) && REVERSE.is(expr.arg(0)))
83
return cc.function(_UTIL_INIT, info, expr.arg(0).args());
basex-core/src/main/java/org/basex/query/func/fn/FnSort.java
@@ -135,6 +135,11 @@ protected Expr opt(final CompileContext cc) throws QueryException {
135
final SeqType st = expr1.arg(0).seqType();
136
if(st.zeroOrOne() && st.type.isSortable()) return expr1;
137
}
138
+ if(REVERSE.is(expr1) || SORT.is(expr1)) {
139
+ final Expr[] args = exprs.clone();
140
+ args[0] = args[0].arg(0);
141
+ return cc.function(SORT, info, args);
142
+ }
143
if(exprs.length == 3) {
144
exprs[2] = coerceFunc(exprs[2], cc, SeqType.ANY_ATOMIC_TYPE_ZM, st1.with(Occ.EXACTLY_ONE));
145
basex-core/src/main/java/org/basex/query/func/util/UtilDdo.java
@@ -46,6 +46,8 @@ protected Expr opt(final CompileContext cc) throws QueryException {
46
if(type instanceof NodeType) {
47
// util:ddo(util:replicate(*, 2)) -> util:ddo(*)
48
if(_UTIL_REPLICATE.is(expr) && ((UtilReplicate) expr).singleEval(false)) return expr.arg(0);
49
+ // util:ddo(reverse(*)) -> util:ddo(*)
50
+ if(REVERSE.is(expr) || SORT.is(expr)) return cc.function(_UTIL_DDO, info, expr.arg(0));
51
// util:ddo(/a/b/c) -> /a/b/c
52
if(expr.ddo()) return expr;
53
// adopt type of argument
basex-core/src/test/java/org/basex/query/func/FnModuleTest.java
@@ -834,7 +834,8 @@ public final class FnModuleTest extends QueryPlanTest {
834
835
check(func.args(" (<_/>, ('a', 'b'))"),
836
"b\na\n<_/>", empty(func));
837
-
+ check("(<a/>, <b/>)[. = ''] =>" + func.args() + " =>" + func.args(),
838
+ "<a/>\n<b/>", empty(func));
839
840
841
/** Test method. */
basex-core/src/test/java/org/basex/query/func/UtilModuleTest.java
@@ -227,7 +227,19 @@ public final class UtilModuleTest extends QueryPlanTest {
227
final Function func = _UTIL_DDO;
228
query(func.args(" <a/>"), "<a/>");
229
query(func.args(" (<a/>, <b/>)"), "<a/>\n<b/>");
230
- query(func.args(" reverse((<a/>, <b/>))"), "<b/>\n<a/>");
+
231
+ check(func.args(" util:replicate((<a/>, <b/>), 10)"), "<a/>\n<b/>",
232
+ empty(_UTIL_REPLICATE));
233
+ check(func.args(" util:replicate(<a/>, 2, true())"), "<a/>\n<a/>",
234
+ exists(_UTIL_REPLICATE));
235
236
+ check("(<a><b/></a> ! (., *)) => reverse() => " + func.args(),
237
+ "<a>\n<b/>\n</a>\n<b/>", empty(REVERSE));
238
+ check("(<a><b/></a> ! (., *)) => sort() => " + func.args(),
239
+ "<a>\n<b/>\n</a>\n<b/>", empty(SORT));
240
+ check("(<a><b/></a> ! (., *)) => sort() => reverse() => sort() => " + func.args(),
241
+ "<a>\n<b/>\n</a>\n<b/>", empty(SORT), empty(REVERSE));
242
243
error(func.args(1), INVCONVERT_X_X_X);
244
245
0 commit comments