remove from array
BCS
ao at pathlink.com
Tue Feb 27 16:39:33 PST 2007
Reply to Thorsten,
>> <totaly untested code>
>>
>> T[] Remove(T)(T[] arr, int i)
>> {
>> return i==arr.length-1 ? arr[0..$-1] : arr[0..i] ~ arr[i+1 .. $];
>> }
> Sorry, I tried that, and it is too expensive !!
> Because it creates about 3 temporary instances.
> I would say :
> void Remove(T)(inout T[] arr, int i)
> {
> for(uint j = i;j < arr.length-1;++j)
> arr[j] = arr[j+1];
> arr.length = arr.length - 1;
> }
> can someone accelerate this ???
>
It would be kida slow wouldn't it.
I only see one allocate and it's not a temp, where are the others? (BTW slicing
doesn't allocate)
More information about the Digitalmars-d
mailing list