haxe
haxe copied to clipboard
[hl] Fix ArrayBytes not clearing properly after pop/shift/splice
Currently, ArrayBytes.pop/shift/splice do not properly zero the underlying array, causing surprises when resizing it like so:
var a = [for(i in 0...10) i];
while(a.length > 0)
a.pop();
a[9] = 9;
trace(a); // [0,1,2,3,4,5,6,7,8,9]
var a = [for(i in 0...10) i];
a.splice(0, 10);
a[9] = 9;
trace(a); // [0,1,2,3,4,5,6,7,8,9]
var a = [for(i in 0...10) i];
while(a.length > 0)
a.shift();
a[9] = 9;
trace(a); // [9,9,9,9,9,9,9,9,9,9]
In all cases the expected result is [0,0,0,0,0,0,0,0,0,9], which PR fixes
The while might be costly on splice, maybe using a bytes.fill instead would be better ? (might require adding it to byteAccess + multiply the size as in "blit")
I've made changes to use fill instead of a while loop
Thanks !