Skip to content

Commit ad8012f

Browse files
committed
[optimisation] Allow pre-computed context sequence from FilteredExpr and Union expressions to be used
1 parent 271a335 commit ad8012f

File tree

4 files changed

+80
-12
lines changed

4 files changed

+80
-12
lines changed

exist-core/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@
796796
<include>src/main/java/org/exist/dom/persistent/DocumentImpl.java</include>
797797
<include>src/main/java/org/exist/dom/persistent/DocumentSet.java</include>
798798
<include>src/main/java/org/exist/dom/persistent/ElementImpl.java</include>
799+
<include>src/main/java/org/exist/dom/persistent/Match.java</include>
800+
<include>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</include>
799801
<include>src/main/java/org/exist/dom/persistent/NodeProxy.java</include>
800802
<include>src/test/java/org/exist/dom/persistent/NodeTest.java</include>
801803
<include>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</include>
@@ -1080,6 +1082,8 @@
10801082
<exclude>src/main/java/org/exist/dom/persistent/DocumentImpl.java</exclude>
10811083
<exclude>src/main/java/org/exist/dom/persistent/DocumentSet.java</exclude>
10821084
<exclude>src/main/java/org/exist/dom/persistent/ElementImpl.java</exclude>
1085+
<exclude>src/main/java/org/exist/dom/persistent/Match.java</exclude>
1086+
<exclude>src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java</exclude>
10831087
<exclude>src/main/java/org/exist/dom/persistent/NodeProxy.java</exclude>
10841088
<exclude>src/test/java/org/exist/dom/persistent/NodeTest.java</exclude>
10851089
<exclude>src/test/java/org/exist/dom/persistent/PersistentDomTest.java</exclude>

exist-core/src/main/java/org/exist/dom/persistent/Match.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*

exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
/*
2+
* Elemental
3+
* Copyright (C) 2024, Evolved Binary Ltd
4+
*
5+
6+
* https://www.evolvedbinary.com | https://www.elemental.xyz
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; version 2.1.
11+
*
12+
* This library is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this library; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+
*
21+
* NOTE: Parts of this file contain code from 'The eXist-db Authors'.
22+
* The original license header is included below.
23+
*
24+
* =====================================================================
25+
*
226
* eXist-db Open Source Native XML Database
327
* Copyright (C) 2001 The eXist-db Authors
428
*
@@ -107,7 +131,11 @@ public class NewArrayNodeSet extends AbstractArrayNodeSet implements ExtNodeSet,
107131
private NodeProxy nodes[];
108132

109133
public NewArrayNodeSet() {
110-
nodes = new NodeProxy[INITIAL_SIZE];
134+
this(INITIAL_SIZE);
135+
}
136+
137+
public NewArrayNodeSet(final int initialSize) {
138+
nodes = new NodeProxy[initialSize];
111139
}
112140

113141
public NewArrayNodeSet(final NewArrayNodeSet other) {

exist-core/src/main/java/org/exist/xquery/LocationStep.java

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.w3c.dom.Node;
5858
import org.w3c.dom.NodeList;
5959

60+
import javax.annotation.Nullable;
6061
import javax.xml.stream.StreamFilter;
6162
import javax.xml.stream.XMLStreamException;
6263
import javax.xml.stream.XMLStreamReader;
@@ -510,26 +511,37 @@ private Sequence getSelf(final XQueryContext context, final Sequence contextSequ
510511
final MemoryNodeSet nodes = contextSequence.toMemNodeSet();
511512
return nodes.getSelf(test);
512513
}
513-
if (hasPreloadedData() && !test.isWildcardTest()) {
514-
final NodeSet ns;
514+
515+
if (hasPreloadedData()) {
516+
@Nullable final NodeSet ns;
515517
if (contextSequence instanceof NodeSet) {
516518
ns = (NodeSet) contextSequence;
517519
} else {
518520
ns = null;
519521
}
520522

521-
for (final NodeProxy p : currentSet) {
522-
p.addContextNode(contextId, p);
523-
524-
if (ns != null) {
525-
final NodeProxy np = ns.get(p);
526-
527-
if (np != null && np.getMatches() != null) {
528-
p.addMatch(np.getMatches());
523+
final NewArrayNodeSet newCurrentSet = new NewArrayNodeSet(currentSet.getItemCount());
524+
for (NodeProxy p : currentSet) {
525+
if (test.isWildcardTest()) {
526+
if (ns != null) {
527+
@Nullable final NodeProxy np = ns.get(p);
528+
if (np != null) {
529+
p = np;
530+
}
531+
}
532+
} else {
533+
if (ns != null) {
534+
@Nullable final NodeProxy np = ns.get(p);
535+
if (np != null && np.getMatches() != null) {
536+
p.addMatch(np.getMatches());
537+
}
529538
}
530539
}
540+
p.addContextNode(contextId, p);
541+
newCurrentSet.add(p);
531542
}
532-
return currentSet;
543+
currentSet = newCurrentSet;
544+
return newCurrentSet;
533545
}
534546

535547
final NodeSet contextSet = contextSequence.toNodeSet();

0 commit comments

Comments
 (0)