avoid toLower in std.algorithm.sort compare alias

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 24 07:54:47 PDT 2012


On Tuesday, 24 April 2012 at 11:24:44 UTC, Regan Heath wrote:
> On Mon, 23 Apr 2012 16:43:20 +0100, Steven Schveighoffer 
> <schveiguy at yahoo.com> wrote:
>
>> While dealing with unicode in my std.stream rewrite, I've 
>> found that hand-decoding dchars is way faster than using 
>> library calls.
>
> After watching Andrei's talk on generic and generative 
> programming I have to ask, which routines are you avoiding .. 
> it seems we need to make them as good as the hand coded code 
> you've written...

from memory (don't have the code in front of me right now), it 
was std.uni.decode, and using foreach(dchar d; str) (which cannot 
be inlined currently).

IIRC, std.uni.decode was not being inlined.  So I tried 
hand-inlining it (I also discovered some optimizations it was not 
using), and it made a huge difference.

In regards to this discussion, I think icmp can also be improved 
when run on a char array, by doing a byte comparison (no dchar 
decoding) until it finds a difference.  That might be a huge 
speedup.  Right now, all dchars are being decoded, and translated 
to the toLower counterpart.  It may have an opposite effect, 
however, if there are a lot of strings that are equivalent when 
ignoring case, but not exactly the same.

-Steve


More information about the Digitalmars-d-learn mailing list