core: rearrange ptr::swap_nonoverlapping_one
's cases (no functional changes).
This commit is contained in:
parent
5b0ab79116
commit
3c3d3ddde9
1 changed files with 13 additions and 11 deletions
|
@ -473,9 +473,15 @@ pub const unsafe fn swap_nonoverlapping<T>(x: *mut T, y: *mut T, count: usize) {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
|
#[rustc_const_unstable(feature = "const_swap", issue = "83163")]
|
||||||
pub(crate) const unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
|
pub(crate) const unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
|
||||||
// For types smaller than the block optimization below,
|
// Only apply the block optimization in `swap_nonoverlapping_bytes` for types
|
||||||
// just swap directly to avoid pessimizing codegen.
|
// at least as large as the block size, to avoid pessimizing codegen.
|
||||||
if mem::size_of::<T>() < 32 {
|
if mem::size_of::<T>() >= 32 {
|
||||||
|
// SAFETY: the caller must uphold the safety contract for `swap_nonoverlapping`.
|
||||||
|
unsafe { swap_nonoverlapping(x, y, 1) };
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Direct swapping, for the cases not going through the block optimization.
|
||||||
// SAFETY: the caller must guarantee that `x` and `y` are valid
|
// SAFETY: the caller must guarantee that `x` and `y` are valid
|
||||||
// for writes, properly aligned, and non-overlapping.
|
// for writes, properly aligned, and non-overlapping.
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -483,10 +489,6 @@ pub(crate) const unsafe fn swap_nonoverlapping_one<T>(x: *mut T, y: *mut T) {
|
||||||
copy_nonoverlapping(y, x, 1);
|
copy_nonoverlapping(y, x, 1);
|
||||||
write(y, z);
|
write(y, z);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// SAFETY: the caller must uphold the safety contract for `swap_nonoverlapping`.
|
|
||||||
unsafe { swap_nonoverlapping(x, y, 1) };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue