Skip to content

Commit

Permalink
Unwrap Vector.Generic to find ArraySlice
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Dec 28, 2024
1 parent 09386ba commit ba0593a
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,36 @@ final class ArraySlice extends EnsoObject {
private final long start;
private final long end;

private ArraySlice(Object storage, long start, long end) {
if (storage instanceof ArraySlice slice) {
private ArraySlice(Object base, long start, long end) {
var s = findStorage(base);
if (s instanceof ArraySlice slice) {
this.storage = slice.storage;
this.start = slice.start + start;
this.end = Math.min(slice.end, slice.start + end);
} else {
if (CompilerDirectives.inInterpreter()) {
if (!InteropLibrary.getUncached().hasArrayElements(storage)) {
if (!InteropLibrary.getUncached().hasArrayElements(s)) {
throw EnsoContext.get(null)
.raiseAssertionPanic(
null, "ArraySlice needs array-like delegate, but got: " + storage, null);
null, "ArraySlice needs array-like delegate, but got: " + s, null);
}
}

this.storage = storage;
this.storage = s;
this.start = start;
this.end = end;
}
}

private static Object findStorage(Object storage) {
for (; ; ) {
return switch (storage) {
case Vector.Generic gen -> gen.toArray();
case ArraySlice slice -> slice;
default -> storage;
};
}
}

static Vector createOrNull(Object storage, long start, long this_length, long end) {
long slice_start = Math.max(0, start);
long slice_end = Math.min(this_length, end);
Expand Down

0 comments on commit ba0593a

Please sign in to comment.