Skip to content

Commit ba78658

Browse files
committed
autovivification WIP
1 parent 20dcf5a commit ba78658

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/main/java/org/perlonjava/operators/Operator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ public static RuntimeScalar substr(RuntimeScalar runtimeScalar, RuntimeList list
467467
* @return a RuntimeList containing the elements that were removed
468468
*/
469469
public static RuntimeList splice(RuntimeArray runtimeArray, RuntimeList list) {
470+
471+
if (runtimeArray.elements instanceof AutovivificationArray arrayProxy) {
472+
arrayProxy.vivify(runtimeArray);
473+
}
474+
470475
RuntimeList removedElements = new RuntimeList();
471476

472477
int size = runtimeArray.elements.size();

src/main/java/org/perlonjava/runtime/RuntimeArray.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,11 @@ public RuntimeList each() {
401401
* @return The updated array with aliases.
402402
*/
403403
public RuntimeArray setArrayOfAlias(RuntimeArray arr) {
404+
405+
if (this.elements instanceof AutovivificationArray arrayProxy) {
406+
arrayProxy.vivify(this);
407+
}
408+
404409
arr.elements.addAll(this.elements);
405410
return arr;
406411
}
@@ -411,6 +416,11 @@ public RuntimeArray setArrayOfAlias(RuntimeArray arr) {
411416
* @return An iterator over the elements of the array.
412417
*/
413418
public Iterator<RuntimeScalar> iterator() {
419+
420+
if (this.elements instanceof AutovivificationArray arrayProxy) {
421+
arrayProxy.vivify(this);
422+
}
423+
414424
return new RuntimeArrayIterator();
415425
}
416426

0 commit comments

Comments
 (0)