The set_integer_native() vtable method of arrays is implemented inconsistently. The old historical way in Array was to set an initial size. My implementation in SArray OTOH only reserves the needed store, but doesn't change the element count.
new P0, .SArray
set P0, 2
set I0, P0 # SArray.elements()
print I0
new P1, .Array # or .PerlArray
set P1, 2
set I1, P1 # Array.elements()
print I1
print "\n"
end
02


This is bad. But it gets worse: You can do "push P0, x" twice on the SArray, filling the first 2 elements. You can't do that on Array. It would set the element #2 which is beyond the preset element count - push is currently not usable for Array PMCs. (PerlArray works basically like Array but does auto-extend)

I'd like to unify the behavior and get best from these two worlds:
1) can set an initial store size and (if really needed)
2) can set an initial element count, not-yet set values are NULL.

One further note, while at Array/PerlArray: the class dependency is suboptimal. PerlArray isa Array isa list. The underlying list is auto-extending and does no bounds checking. Array does bounds-checking. PerlArray doesn't bounds check. So for better performace and simpler code, the dependency of PerlArray and Array should be swapped.

Comments welcome,
leo



Reply via email to