use swap_unchecked in slice::reverse

This commit is contained in:
ibraheemdev 2021-08-31 21:00:30 -04:00 committed by Ibraheem Ahmed
parent 14769ce96f
commit 33ecc33268

View file

@ -707,11 +707,7 @@ impl<T> [T] {
// The resulting pointers `pa` and `pb` are therefore valid and // The resulting pointers `pa` and `pb` are therefore valid and
// aligned, and can be read from and written to. // aligned, and can be read from and written to.
unsafe { unsafe {
// Unsafe swap to avoid the bounds check in safe swap. self.swap_unchecked(i, ln - i - 1);
let ptr = self.as_mut_ptr();
let pa = ptr.add(i);
let pb = ptr.add(ln - i - 1);
ptr::swap(pa, pb);
} }
i += 1; i += 1;
} }