feat: add list clear and insert primitives with capacity growth and index validation

Extract inline list growth logic into `ensureListCapacity` helper and add `validateIndex` function supporting negative indices. Implement `list_clear` primitive that resets count to zero without freeing memory, and `list_insert` primitive that shifts elements right and inserts at validated position. Add comprehensive test suites for both operations covering empty lists, normal/negative indices, and return values.
This commit is contained in:
Bob Nystrom
2013-11-27 07:11:11 +00:00
parent 91c675b28a
commit 3c3fa2bfd9
3 changed files with 126 additions and 28 deletions
+7
View File
@@ -0,0 +1,7 @@
var a = [1, 2, 3]
a.clear
io.write(a) // expect: []
io.write(a.count) // expect: 0
// Returns null.
io.write([1, 2].clear) // expect: null