Sorts inputs of at most 20 elements with a guarded insertion sort, checks whether a single pre-sorted run covers the whole input (reversing it when strictly descending), then quicksorts with a pseudo-median pivot sampled as in Glidesort, falling back to Heapsort after 2⌊log₂ n⌋ partitions.
The partition is a branchless Lomuto loop paired with a cyclic permutation — two moves per element and no data-dependent branch on the classification. A pivot equal to the left-ancestor pivot triggers an equal-partition pass that removes the whole pivot-equal block from the recursion, giving O(n log k) behavior for k distinct values. The algorithm behind Rust's unstable sort since 1.81.