You can use
setcapacity to avoid resizings. Clone avoids sorting the keys, I assume.
Insertat(1) will shift all key-value pairs already in the array, on every call.
Edit:
With shifting paris I mean figurative,
{1:"a"}.insertat(1,"b") -> {1:"b", 2:"a"} .... I don't think the values are moved in memory, I would guess no.
Also, an alternative, I think it will perform similar to the
clone variants,
Code: Select all
rev(arr){
sa:=(l:=arr.length())//2 ; Edit
for k, v in arr
arr[k]:=arr[l-k+1],arr[l-k+1]:=v
until k==sa
return
} ; Briefly tested.
If the content of
arr are very big strings, we avoid having duplicates of all of them at the same time.
Edit: Fixed weird mistake. It should work now.