avoid toLower in std.algorithm.sort compare alias

Jonathan M Davis jmdavisProg at gmx.com
Tue Apr 24 14:04:06 PDT 2012


On Tuesday, April 24, 2012 12:24:44 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...

In general, when operating on strings generically, you up having to treat them 
as ranges of dchar and decode everything, but there are a lot of cases where 
you can special-case algorithms for narrow strings and avoid decoding them. 
Phobos does this a lot (though it can probably do a better job of it in a 
number of places), so by using functions from there rather than rolling your 
own, the problem is reduced, but any time that you're doing a lot of generic 
string processing, there's a decent chance that you're going to have to 
special case some stuff for arrays of char, wchar, and dchar in order to fully 
optimize it. And I don't think that there's really a way out of that beyond 
having a lot of functions already available (and already optimized) to do a 
lot of the string processing for you. There's a definite tension between 
genericity and effciency in the case of string processing - due primarily to 
variable length encodings.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list