V2 string

Walter Bright newshound1 at digitalmars.com
Thu Jul 5 17:26:51 PDT 2007


BCS wrote:
> The one issue I can see with this is where an input is const but may be 
> changed (and .duped) at any of a number of points. The data though only 
> needs to be .duped once.
> 
> |char[] Whatever(const char[] str)
> |{
> | if(c1) str = Mod1(str.dup);
> | if(c2) str = Mod2(str.dup);
> | if(c3) str = Mod3(str.dup);
> | return str;
> |}
> // causes exces duping

My experience with this is:

1) Such cases are unusual

2) The few cases where they do happen, they are not in that 5% of the 
code that is a bottleneck

3) If such code is performance critical, there's usually a better way to 
write it that will yield even better performance than taking repeated 
passes over the same string. Best performance usually comes by merging 
all the operations into one pass.



More information about the Digitalmars-d mailing list