This recent patch:
Added quick_sort_locations(). This replaces some O(n^2) algorithms with some that are O(n log(n))
Tries to optimise an O(n^2) operation to O(n log(n)), yet uses quicksort in the process which can be O(n^2) all by itself. Why not use (my personal favourite): heapsort? Heapsort is O(n log(n)) as the *worst* case.
Though Grubba's commit message didn't reveal so the change is only related to dmalloc. And speaking of algorithms, check out Introsort which is a O(n lg n) hybrid of quicksort and heapsort (already used elsewhere in Pike if I remember correctly).
In this case, the sorting key appears to be a fixed size integer, which means you could use radixsort, which is O(n)... ;-)
pike-devel@lists.lysator.liu.se