in reply to Re: Refactor my sort
in thread Refactor my sort

Looking at it, you are probably right that my code would be a good candidate for this. However I am reading the documentation, and I will be honest, I don't understand it.

Replies are listed 'Best First'.
Re^3: Refactor my sort
by roboticus (Chancellor) on Dec 22, 2006 at 19:52 UTC
    Herkum:

    My take on it is this: the comparison operator on a string is a bit slow since it has to take locale and such into account. The GRT basically packs the data into a string of bytes such that a simple numeric comparison would reliably sort the data.

    This saves you time because rather than go through the locale-conversion code to order the strings each time they're accessed, you perform the conversion once (during pack), then you just treat the keys as integers X bytes long, which are much simpler to compare.

    --roboticus

      The GRT packs the data into a string, yes, but I'm pretty sure the sort is then lexical, not numeric. I believe that pack is the usual tool for creating the string but GrandFather did one here that used sprintf.

      Cheers,

      JohnGG