On Wednesday, 9 April 2014 at 23:43:27 UTC, bearophile wrote:
dnspies:
efficiently, or is it better to avoid this sort of thing?
D arrays are dynamic on the right. So appending on their left
is not efficient (also here you are not prepending, you are
concatenating. Array concatenation creates a new array). In
some cases you can append on the right many items and then use
std.algorithm.reverse (don't forget the () if you use UFCS) to
reverse them. In case of doubt write little benchmarks.
Bye,
bearophile
Does concatenation always create a new array? What if the type
of the original is immutable (or even const)? In that case,
wouldn't it be worthwhile to check first if rhs can be copied to
the right of lhs?