V2 string

Regan Heath regan at netmail.co.nz
Fri Jul 6 01:26:46 PDT 2007


Walter Bright wrote:
> Regan Heath wrote:
>> Walter Bright Wrote:
>>> string fullpath;
>>>
>>> fullpath = CanonicalPath(shortname);
>>> version(Windows)
>>> {
>>>        fullpath = std.string.tolower(fullpath);
>>> }
>>>
>>> you won't need to do the .dup .
>>
>> Because tolower does it for you, but it still returns string
> 
> tolower only dups the string if it needs to. It won't dup a string that 
> is already in lower case.

Sure, but there is still a case where it does dup.  (dup #1)

>  > and if for example
>  > you need to add something to the end of the path, like a filename you 
>  > will end up
>  > doing yet another dup somewhere.
> 
> Concatenating strings does not require a .dup.

opCatAssign does. (dup #2)

OR

newString = constString ~ bitToAdd; (is a copy of constString to 
newString which is essentially a dup) (dup #2)

So, the worst case scenario is that 2 dups are done.

Further if the input is char[] you can still get this worst case 
scenario because tolower returns string instead of char[].  With a 
templated version you get a much more efficient tolower for char[].

Regan



More information about the Digitalmars-d mailing list