Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions library/core/src/slice/rotate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::mem::{MaybeUninit, SizedTypeProperties};
use crate::ptr;
use crate::{cmp, ptr};

type BufType = [usize; 32];

Expand All @@ -11,6 +11,7 @@ type BufType = [usize; 32];
///
/// The specified range must be valid for reading and writing.
#[inline]
#[rustc_allow_const_fn_unstable(const_trait_impl, const_cmp)]
pub(super) const unsafe fn ptr_rotate<T>(left: usize, mid: *mut T, right: usize) {
if T::IS_ZST {
return;
Expand All @@ -21,8 +22,7 @@ pub(super) const unsafe fn ptr_rotate<T>(left: usize, mid: *mut T, right: usize)
}
// `T` is not a zero-sized type, so it's okay to divide by its size.
if !cfg!(feature = "optimize_for_size")
// FIXME(const-hack): Use cmp::min when available in const
&& const_min(left, right) <= size_of::<BufType>() / size_of::<T>()
&& cmp::min(left, right) <= size_of::<BufType>() / size_of::<T>()
{
// SAFETY: guaranteed by the caller
unsafe { ptr_rotate_memmove(left, mid, right) };
Expand Down Expand Up @@ -270,8 +270,3 @@ const unsafe fn ptr_rotate_swap<T>(mut left: usize, mut mid: *mut T, mut right:
}
}
}

// FIXME(const-hack): Use cmp::min when available in const
const fn const_min(left: usize, right: usize) -> usize {
if right < left { right } else { left }
}
Loading