Skip to content

Commit f132761

Browse files
[MOD] Arrays & Maps: improved size estimations
1 parent 4817250 commit f132761

16 files changed

+32
-20
lines changed

basex-core/src/main/java/org/basex/query/func/array/ArrayAppend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected Expr opt(final CompileContext cc) throws QueryException {
3737

3838
@Override
3939
public long structSize() {
40-
final long as = arg(0).structSize();
40+
final long as = structSize(0);
4141
return as != -1 ? as + 1 : -1;
4242
}
4343
}

basex-core/src/main/java/org/basex/query/func/array/ArrayFn.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import static org.basex.query.QueryError.*;
44

55
import org.basex.query.*;
6+
import org.basex.query.expr.*;
67
import org.basex.query.func.*;
78
import org.basex.query.value.array.*;
9+
import org.basex.query.value.type.*;
810

911
/**
1012
* Functions on arrays.
@@ -26,4 +28,14 @@ final long toPos(final XQArray array, final long pos, final boolean incl) throws
2628
if(pos > 0 && pos <= size) return pos - 1;
2729
throw (size == 0 ? ARRAYEMPTY : ARRAYBOUNDS_X_X).get(info, pos, size);
2830
}
31+
32+
/**
33+
* Returns the size of the array passed via the specified argument.
34+
* @param a index of argument
35+
* @return array size
36+
*/
37+
final long structSize(final int a) {
38+
final Expr expr1 = arg(a);
39+
return expr1.seqType().instanceOf(Types.ARRAY_O) ? expr1.structSize() : -1;
40+
}
2941
}

basex-core/src/main/java/org/basex/query/func/array/ArrayForEach.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected Expr opt(final CompileContext cc) throws QueryException {
4848

4949
@Override
5050
public long structSize() {
51-
return arg(0).structSize();
51+
return structSize(0);
5252
}
5353

5454
@Override

basex-core/src/main/java/org/basex/query/func/array/ArrayForEachPair.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected Expr opt(final CompileContext cc) throws QueryException {
5353

5454
@Override
5555
public long structSize() {
56-
final long as1 = arg(0).structSize(), as2 = arg(0).structSize();
56+
final long as1 = structSize(0), as2 = structSize(1);
5757
return as1 != -1 && as2 != -1 ? Math.min(as1, as2) : -1;
5858
}
5959

basex-core/src/main/java/org/basex/query/func/array/ArrayInsertBefore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected ArrayInsertBefore opt(final CompileContext cc) {
3333

3434
@Override
3535
public long structSize() {
36-
final long as = arg(0).structSize();
36+
final long as = structSize(0);
3737
return as != -1 ? as + 1 : -1;
3838
}
3939
}

basex-core/src/main/java/org/basex/query/func/array/ArrayMembers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected Expr opt(final CompileContext cc) {
5555
final Expr array = arg(0);
5656
final Type type = array.seqType().type;
5757
if(type instanceof final ArrayType at) {
58-
exprType.assign(cc.qc.shared.record(Str.VALUE, at.valueType()));
58+
exprType.assign(cc.qc.shared.record(Str.VALUE, at.valueType()).seqType(), array.structSize());
5959
}
6060
return this;
6161
}

basex-core/src/main/java/org/basex/query/func/array/ArrayPut.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ protected Expr opt(final CompileContext cc) {
3333

3434
@Override
3535
public long structSize() {
36-
return arg(0).structSize();
36+
return structSize(0);
3737
}
3838
}

basex-core/src/main/java/org/basex/query/func/array/ArrayRemove.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected Expr opt(final CompileContext cc) {
5151

5252
@Override
5353
public long structSize() {
54-
final long as = arg(0).structSize();
54+
final long as = structSize(0);
5555
return as != -1 ? as - 1 : -1;
5656
}
5757
}

basex-core/src/main/java/org/basex/query/func/array/ArrayReverse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ protected Expr opt(final CompileContext cc) {
2828

2929
@Override
3030
public long structSize() {
31-
return arg(0).structSize();
31+
return structSize(0);
3232
}
3333
}

basex-core/src/main/java/org/basex/query/func/array/ArraySort.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public int hofIndex() {
4343

4444
@Override
4545
public long structSize() {
46-
return arg(0).structSize();
46+
final Expr expr1 = arg(0);
47+
return expr1.seqType().instanceOf(Types.ARRAY_O) ? expr1.structSize() : -1;
4748
}
4849
}

0 commit comments

Comments
 (0)