From 33ecc33268c1cda372c90c203cead2721a822363 Mon Sep 17 00:00:00 2001 From: ibraheemdev Date: Tue, 31 Aug 2021 21:00:30 -0400 Subject: [PATCH] use `swap_unchecked` in `slice::reverse` --- library/core/src/slice/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 16e3c9e52fa9..496cc359c19f 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -707,11 +707,7 @@ impl [T] { // The resulting pointers `pa` and `pb` are therefore valid and // aligned, and can be read from and written to. unsafe { - // Unsafe swap to avoid the bounds check in safe swap. - let ptr = self.as_mut_ptr(); - let pa = ptr.add(i); - let pb = ptr.add(ln - i - 1); - ptr::swap(pa, pb); + self.swap_unchecked(i, ln - i - 1); } i += 1; }