Skip to content

Commit 1b8e922

Browse files
committed
[bugfix] Fix a bug in removing duplicate in-memory nodes from a sequence
1 parent 50bce69 commit 1b8e922

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

exist-core/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@
14191419
<include>src/main/java/org/exist/xquery/value/TimeUtils.java</include>
14201420
<include>src/main/java/org/exist/xquery/value/TimeValue.java</include>
14211421
<include>src/main/java/org/exist/xquery/value/Type.java</include>
1422+
<include>src/main/java/org/exist/xquery/value/ValueSequence.java</include>
14221423
<include>src/test/java/org/exist/xquery/value/YearMonthDurationTest.java</include>
14231424
<include>src/main/java/org/exist/xquery/value/YearMonthDurationValue.java</include>
14241425
<include>src/main/java/org/exist/xslt/EXistURIResolver.java</include>
@@ -2234,6 +2235,7 @@
22342235
<exclude>src/main/java/org/exist/xquery/value/TimeUtils.java</exclude>
22352236
<exclude>src/main/java/org/exist/xquery/value/TimeValue.java</exclude>
22362237
<exclude>src/main/java/org/exist/xquery/value/Type.java</exclude>
2238+
<exclude>src/main/java/org/exist/xquery/value/ValueSequence.java</exclude>
22372239
<exclude>src/test/java/org/exist/xquery/value/YearMonthDurationTest.java</exclude>
22382240
<exclude>src/main/java/org/exist/xquery/value/YearMonthDurationValue.java</exclude>
22392241
<exclude>src/main/java/org/exist/xslt/EXistURIResolver.java</exclude>

exist-core/src/main/java/org/exist/xquery/value/ValueSequence.java

Lines changed: 28 additions & 6 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+
* admin@evolvedbinary.com
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
*
@@ -455,15 +479,13 @@ private void removeDuplicateNodes() {
455479
return;
456480
}
457481
if (inMemNodeSet) {
458-
int j = 0;
482+
int writeIdx = 1;
459483
for (int i = 1; i <= size; i++) {
460-
if (!values[i].equals(values[j])) {
461-
if (i != ++j) {
462-
values[j] = values[i];
463-
}
484+
if (!values[i].equals(values[i - 1])) {
485+
values[writeIdx++] = values[i];
464486
}
465487
}
466-
size = j;
488+
size = writeIdx - 1;
467489
} else {
468490
if (itemType != Type.ANY_TYPE && Type.subTypeOf(itemType, Type.ATOMIC)) {
469491
return;

0 commit comments

Comments
 (0)