Skip to content

Commit bf86185

Browse files
committed
[optimize] Make combining two NodeListImpl more efficient
1 parent b467f03 commit bf86185

File tree

2 files changed

+62
-8
lines changed

2 files changed

+62
-8
lines changed

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,7 @@
828828
<include>src/main/java/org/exist/config/Configuration.java</include>
829829
<include>src/main/java/org/exist/config/ConfigurationImpl.java</include>
830830
<include>src/main/java/org/exist/config/Configurator.java</include>
831+
<include>src/main/java/org/exist/dom/NodeListImpl.java</include>
831832
<include>src/main/java/org/exist/dom/memtree/AttrImpl.java</include>
832833
<include>src/main/java/org/exist/dom/memtree/DocumentImpl.java</include>
833834
<include>src/main/java/org/exist/dom/memtree/DOMIndexer.java</include>
@@ -1101,6 +1102,7 @@
11011102
<exclude>src/main/java/org/exist/config/Configuration.java</exclude>
11021103
<exclude>src/main/java/org/exist/config/ConfigurationImpl.java</exclude>
11031104
<exclude>src/main/java/org/exist/config/Configurator.java</exclude>
1105+
<exclude>src/main/java/org/exist/dom/NodeListImpl.java</exclude>
11041106
<exclude>src/main/java/org/exist/dom/memtree/AttrImpl.java</exclude>
11051107
<exclude>src/main/java/org/exist/dom/memtree/DocumentImpl.java</exclude>
11061108
<exclude>src/main/java/org/exist/dom/memtree/DocumentTypeImpl.java</exclude>

exist-core/src/main/java/org/exist/dom/NodeListImpl.java

Lines changed: 60 additions & 8 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
*
@@ -46,6 +70,26 @@ public boolean add(final Node node) {
4670
return super.add(node);
4771
}
4872

73+
/**
74+
* Add all elements of the other NodeListImpl to
75+
* this NodeListImpl.
76+
*
77+
* @param other NodeListImpl to add.
78+
*
79+
* @return true if the list was modified, false otherwise.
80+
*/
81+
public boolean addAll(final NodeListImpl other) {
82+
if (other == null) {
83+
return false;
84+
}
85+
86+
if (other.isEmpty()) {
87+
return false;
88+
}
89+
90+
return addAll((ArrayList<Node>) other);
91+
}
92+
4993
/**
5094
* Add all elements of the other NodeList to
5195
* this NodeList
@@ -54,18 +98,26 @@ public boolean add(final Node node) {
5498
* if none or only some were added.
5599
*/
56100
public boolean addAll(final NodeList other) {
101+
if (other == null) {
102+
return false;
103+
}
104+
105+
if (other instanceof NodeListImpl) {
106+
return addAll((NodeListImpl) other);
107+
}
108+
57109
if (other.getLength() == 0) {
58110
return false;
59-
} else {
60-
boolean result = true;
61-
for(int i = 0; i < other.getLength(); i++) {
62-
if(!add(other.item(i))) {
63-
result = false;
64-
break;
65-
}
111+
}
112+
113+
boolean result = true;
114+
for (int i = 0; i < other.getLength(); i++) {
115+
if (!add(other.item(i))) {
116+
result = false;
117+
break;
66118
}
67-
return result;
68119
}
120+
return result;
69121
}
70122

71123
@Override

0 commit comments

Comments
 (0)