Skip to content

Commit

Permalink
Auto merge of #129587 - Voultapher:opt-for-size-variants-of-sort-impl…
Browse files Browse the repository at this point in the history
…s, r=cuviper

Add `optimize_for_size` variants for stable and unstable sort as well as select_nth_unstable

- Stable sort uses a simple merge-sort that re-uses the existing - rather gnarly - merge function.
- Unstable sort jumps directly to the branchless heapsort fallback.
- select_nth_unstable jumps directly to the median_of_medians fallback, which is augmented with a custom tiny smallsort and partition impl.

Some code is duplicated but de-duplication would bring it's own problems. For example `swap_if_less` is critical for performance, if the sorting networks don't inline it perf drops drastically, however `#[inline(always)]` is also a poor fit, if the provided comparison function is huge, it gives the compiler an out to only instantiate `swap_if_less` once and call it. Another aspect that would suffer when making `swap_if_less` pub, is having to cfg out dozens of functions in in smallsort module.

Part of rust-lang/rust#125612

r​? `@Kobzol`
  • Loading branch information
bors committed Sep 24, 2024
2 parents 789bfcc + 1d6fa6f commit 5a703eb
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 5a703eb

Please sign in to comment.