core/slice/sort/shared/
mod.rs#![cfg_attr(any(feature = "optimize_for_size", target_pointer_width = "16"), allow(dead_code))]
use crate::marker::Freeze;
pub(crate) mod pivot;
pub(crate) mod smallsort;
#[rustc_unsafe_specialization_marker]
pub(crate) trait FreezeMarker {}
impl<T: Freeze> FreezeMarker for T {}
#[inline(always)]
pub(crate) fn find_existing_run<T, F: FnMut(&T, &T) -> bool>(
v: &[T],
is_less: &mut F,
) -> (usize, bool) {
let len = v.len();
if len < 2 {
return (len, false);
}
unsafe {
let mut run_len = 2;
let strictly_descending = is_less(v.get_unchecked(1), v.get_unchecked(0));
if strictly_descending {
while run_len < len && is_less(v.get_unchecked(run_len), v.get_unchecked(run_len - 1)) {
run_len += 1;
}
} else {
while run_len < len && !is_less(v.get_unchecked(run_len), v.get_unchecked(run_len - 1))
{
run_len += 1;
}
}
(run_len, strictly_descending)
}
}