COW vs. in-place.

Dawid Ciężarkiewicz dawid.ciezarkiewicz at gmail.com
Tue Aug 1 07:06:30 PDT 2006


Lionello Lunesu wrote:

> 
> "Dave" <Dave_member at pathlink.com> wrote in message
> news:ealack$bjg$1 at digitaldaemon.com...
>>
>> What if selected functions in phobos were modified to take an optional
>> parameter that specified COW or in-place? The default for each would be
>> whatever they do now.
>>
>> For example, toupper and tolower?
>>
>> How many times have we seen something like this:
>>
>> str = toupper(str); // or equivalent in another language.
> 
> str being an UTF-8 string, I don't think you can guarantee that it CAN be
> made uppercase in-place. It seems to me that it's quite possible that some
> uppercase UNICODE characters are larger than their lowercase versions,
> possibly crossing an UTF-8 byte-count border. But there are other string
> functions that don't have this problem.

This _is_ problem.

> In either case, a standard library should simply provide two functions,
> one in-place and the other COW. I many cases, the COW function could use
> the in-place one, eliminating duplicate code. For example, In my own lib I
> use .ToUpper() for the in-place version and .UpperCase() for the COW one.

Well thought.



More information about the Digitalmars-d mailing list