If T[new] is the container for T[], then what is the container for T[U]?

Rainer Deyke rainerd at eldwood.com
Sun Apr 26 00:21:08 PDT 2009


Robert Jacques wrote:
> 1) Immutable strings are often concatenated, which you don't address

There are two types of concatenation: in-place (operator ~=) and not
(operator ~).  The former can take advantage of capacity to avoid new
allocation, the latter can not.

When concatenating a lot of immutable strings, it might make sense to
make the left side mutable:

char[] tmp = string1.dup;
tmp ~= string2;
tmp ~= string3;
// ...
tmp ~= string99;
string result = tmp.idup;

> 2) int[], real[], and basically anything not a string rarely
> concatenates, but often mutable, which you don't address

I frequently append individual elements to non-string arrays.


-- 
Rainer Deyke - rainerd at eldwood.com



More information about the Digitalmars-d mailing list