When pre-sorting a regular file, use lib/arraysort.h on an array of items
instead of the default merge-sort type algorithm working with linked lists.
This is much faster -- e.g., the sorting in shep-export on the current
Sherlock3 database now takes 54 sec instead of 669 :-)
However, to accomplish this I had to change two invariants:
(1) SORT_REGULAR now means not only that the input has regular structure,
but also that each item is reasonably small (i.e., we can use
sorting by exchanging in place).
(2) If SORT_PRESORT is enabled, the comparison function can be called
with both keys equal. This trips ASSERT's on various place which
originally helped a lot during debugging, so I decided to add
a SORT_UNIQUE switch which in DEBUG mode causes the sorter to
ensure that all keys are distinct, so we can remove the ASSERT's.
As both the Shepherd and the Indexer now rely heavily on sorting, it might
be worth a try to optimize the sorter even further, maybe by utilizing
polyphase sorting or something like that, the run sizes really seem to be
distributed unevenly many times.