Skip to content

Commit

Permalink
Ensure small-sort is inlined
Browse files Browse the repository at this point in the history
This greatly improves binary-size. With the recent change we made sure
to only call the small-sort once. While we don't expect the
stable_quicksort loop to be inline-able because it is recursive. We want
to be on the safe side and annotate it.
  • Loading branch information
Voultapher committed Feb 26, 2024
1 parent 445813e commit d3e325e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/quicksort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::smallsort::SmallSortTypeImpl;
///
/// `limit` when initialized with `c*log(v.len())` for some c ensures we do not
/// overflow the stack or go quadratic.
#[inline(never)]
pub fn stable_quicksort<T, F: FnMut(&T, &T) -> bool>(
mut v: &mut [T],
scratch: &mut [MaybeUninit<T>],
Expand Down
2 changes: 2 additions & 0 deletions src/smallsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub trait SmallSortTypeImpl: Sized {
impl<T> SmallSortTypeImpl for T {
default const SMALL_SORT_THRESHOLD: usize = 16;

#[inline(always)]
default fn sort_small<F: FnMut(&T, &T) -> bool>(
v: &mut [T],
_scratch: &mut [MaybeUninit<T>],
Expand All @@ -44,6 +45,7 @@ where
{
const SMALL_SORT_THRESHOLD: usize = 20;

#[inline(always)]
fn sort_small<F: FnMut(&T, &T) -> bool>(
v: &mut [T],
scratch: &mut [MaybeUninit<T>],
Expand Down

0 comments on commit d3e325e

Please sign in to comment.