Skip to content
Open
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
16 changes: 5 additions & 11 deletions library/core/src/slice/sort/shared/smallsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fn small_sort_general_with_scratch<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(
// permutation of the input through drop_guard. This technique is similar
// to ping-pong merging.
bidirectional_merge(
&*ptr::slice_from_raw_parts(drop_guard.src, drop_guard.len),
slice::from_raw_parts(drop_guard.src, drop_guard.len),
drop_guard.dst,
is_less,
);
Expand Down Expand Up @@ -332,7 +332,7 @@ where
let v_base = v.as_mut_ptr();
let initial_region_len = if no_merge { len } else { len_div_2 };
// SAFETY: Both possible values of `initial_region_len` are in-bounds.
let mut region = unsafe { &mut *ptr::slice_from_raw_parts_mut(v_base, initial_region_len) };
let mut region = unsafe { slice::from_raw_parts_mut(v_base, initial_region_len) };

// Avoid compiler unrolling, we *really* don't want that to happen here for binary-size reasons.
loop {
Expand All @@ -357,21 +357,15 @@ where
}

// SAFETY: The right side of `v` based on `len_div_2` is guaranteed in-bounds.
unsafe {
region = &mut *ptr::slice_from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2)
};
unsafe { region = slice::from_raw_parts_mut(v_base.add(len_div_2), len - len_div_2) };
}

// SAFETY: We checked that T is Freeze and thus observation safe.
// Should is_less panic v was not modified in parity_merge and retains it's original input.
// scratch and v must not alias and scratch has v.len() space.
unsafe {
let scratch_base = stack_array.as_mut_ptr() as *mut T;
bidirectional_merge(
&mut *ptr::slice_from_raw_parts_mut(v_base, len),
scratch_base,
is_less,
);
bidirectional_merge(slice::from_raw_parts_mut(v_base, len), scratch_base, is_less);
ptr::copy_nonoverlapping(scratch_base, v_base, len);
}
}
Expand Down Expand Up @@ -675,7 +669,7 @@ unsafe fn sort8_stable<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(
// SAFETY: scratch_base[0..8] is now initialized, allowing us to merge back
// into dst.
unsafe {
bidirectional_merge(&*ptr::slice_from_raw_parts(scratch_base, 8), dst, is_less);
bidirectional_merge(slice::from_raw_parts(scratch_base, 8), dst, is_less);
}
}

Expand Down
Loading