avoid toLower in std.algorithm.sort compare alias

Marco Leise Marco.Leise at gmx.de
Wed Apr 25 23:01:58 PDT 2012


Am Sun, 22 Apr 2012 09:23:45 +0200
schrieb "Jay Norwood" <jayn at prismnet.com>:

> On Sunday, 22 April 2012 at 06:26:42 UTC, Jonathan M Davis wrote:
> >
> > You can look at the code. It checks each of the characters in 
> > place. Unlike
> > toLower, it doesn't need to generate a new string. But as far 
> > as the
> > comparison goes, they're the same - hence that line in the docs.
> >
> > - Jonathan M Davis
> 
> ok, I did look at the code just now, and I'll sleep better
> knowing that it doesn't do the whole string conversion.  I
> misunderstood your pseudo-code to mean that two lower case
> strings were being created prior to the compare.
> 
> However,  icmp code does appear to call the toLower conversion on
> both characters without first comparing the characters for
> equality, which misses the chance to do a simple compare that
> would avoid the two calls.

        /----- check for equality :)
        v
cmp!"a != b && std.uni.toLower(a) < std.uni.toLower(b)"(r1, r2)

-- 
Marco



More information about the Digitalmars-d-learn mailing list