Successively prepending to slices.
John Colvin
john.loughran.colvin at gmail.com
Thu Apr 10 02:28:28 PDT 2014
On Wednesday, 9 April 2014 at 23:18:27 UTC, dnspies wrote:
> I know that D slices are set up so you can successively append
> to them and it only has to re-allocate infrequently, but what
> about with prepending?
>
> ie, does D have a way to handle
>
> int[] x;
> for(int i=0; i < 1000; i++) {
> x = [i] ~ x;
> }
>
> efficiently, or is it better to avoid this sort of thing?
Definitely better to avoid. What's the use-case? There is almost
certainly a better way of achieving what you want.
More information about the Digitalmars-d-learn
mailing list