Specialize intarray sorting
authorJohn Naylor <[email protected]>
Tue, 18 Feb 2025 04:04:55 +0000 (11:04 +0700)
committerJohn Naylor <[email protected]>
Tue, 18 Feb 2025 04:04:55 +0000 (11:04 +0700)
commit53d3daa491be458e543dd5bf24d40595e588e4e7
tree2dd02a2a3cefa844c90dd047bb95dae80b9f9ede
parent164bac92f08ccddd6701d44a5338d72c22f7b5c2
Specialize intarray sorting

There is at least one report in the field of storing millions of
integers in arrays, so it seems like a good time to specialize
intarray's qsort function. In doing so, streamline the comparators:
Previously there were three, two for each direction for sorting
and one passed to qunique_arg. To preserve the early exit in the
case of descending input, pass the direction as an argument to
the comparator. This requires giving up duplicate detection, which
previously allowed skipping the qunique_arg() call. Testing showed
no regressions this way.

In passing, get rid of nearby checks that the input has at least
two elements, since preserving them would make some macros less
readable. These are not necessary for correctness, and seem like
premature optimizations.

Author: Andrey M. Borodin <[email protected]>
Discussion: https://postgr.es/m/098A3E67-E4A6-4086-9C66-B1EAEB1DFE1C@yandex-team.ru
contrib/intarray/_int.h
contrib/intarray/_int_tool.c