String Prefix Predicate
    Jonathan M Davis via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Aug 14 11:07:39 PDT 2014
    
    
  
On Thursday, 14 August 2014 at 17:41:08 UTC, Nordlöw wrote:
> On Thursday, 14 August 2014 at 17:33:41 UTC, Justin Whear wrote:
>> std.algorithm.startsWith?  Should auto-decode, so it'll do a
>
> What about 
> https://github.com/D-Programming-Language/phobos/pull/2043
>
> Auto-decoding should be avoided when possible.
>
> I guess something like
>
> whole.byDchar().startsWith(part.byDchar())
>
> is preferred right?
>
> If so is this what we will live with until Phobos has been 
> upgraded to using pull 2043 in a few years?
Except that you _have_ to decode in this case. Unless the string 
types match, there's no way around it. And startsWith won't 
decode if the string types match. So, I really see no issue in 
just straight-up using startsWith.
Where you run into problems with auto-decoding in Phobos 
functions is when a function results in a new range type. That 
forces you into a range of dchar, whether you wanted it or not. 
But beyond that, Phobos is actually pretty good about avoiding 
unnecessary decoding (though there probably are places where it 
could be improved). The big problem is that that requires 
special-casing a lot of functions, whereas that wouldn't be 
required with a range of char or wchar.
So, the biggest problems with automatic decoding are when a 
function returns a range of dchar when you wanted to operate on 
code units or when you write a function and then have to special 
case it for strings if you want to avoid the auto-decoding, 
whereas that's already been done for you with most Phobos 
functions.
- Jonathan M Davis
    
    
More information about the Digitalmars-d-learn
mailing list