avoid toLower in std.algorithm.sort compare alias

Jacob Carlborg doob at me.com
Sun Apr 22 03:16:49 PDT 2012


On 2012-04-22 01:24, Jay Norwood wrote:
> While playing with sorting the unzip archive entries I tried use of the
> last example in http://dlang.org/phobos/std_algorithm.html#sort
>
> std.algorithm.sort!("toLower(a.name) <
> toLower(b.name)",std.algorithm.SwapStrategy.stable)(entries);
>
> It was terribly slow for sorting the 34k entries in my test case. I'd
> guess it is doing the toLower call on both strings for every compare.
>
> It was much, much faster to add an entries.lowerCaseName =
> std.string.toLower(entries.name) foreach entry prior to the sort
> execution and then use
>
> std.algorithm.sort!("a.lowerCaseName < b.lowerCaseName
> ",std.algorithm.SwapStrategy.stable)(entries);
>
> The difference was on the order of 10 secs vs no noticeable delay when
> executing the sort operation in the debugger.

Perhaps a function that does case folding would be better in this case. 
But as far as I know Phobos doesn't have a function for that.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list