fix: small issue with sparse arrays

This commit is contained in:
TopchetoEU 2024-01-06 17:46:13 +02:00
parent a321fc14bc
commit 918f2623cd
Signed by: topchetoeu
GPG Key ID: 6531B8583E5F6ED4

View File

@ -84,6 +84,8 @@ public class ArrayValue extends ObjectValue implements Iterable<Object> {
}
public void copyTo(Context ctx, ArrayValue arr, int sourceStart, int destStart, int count) {
// Iterate in reverse to reallocate at most once
if (destStart + count > arr.size) arr.size = destStart + count;
for (var i = count - 1; i >= 0; i--) {
if (i + sourceStart < 0 || i + sourceStart >= size) arr.remove(i + destStart);
if (values[i + sourceStart] == UNDEFINED) arr.set(ctx, i + destStart, null);