From 26cfd211fb00f7f9076bf12eb3eef4da341720d3 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 14 Aug 2023 09:53:53 +0200 Subject: [PATCH] simplify is_nonoverlapping a bit --- library/core/src/intrinsics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 9ef2c7cde02e..0442e1639bac 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -2568,7 +2568,7 @@ pub(crate) fn is_nonoverlapping(src: *const T, dst: *const T, count: usize) - let size = mem::size_of::() .checked_mul(count) .expect("is_nonoverlapping: `size_of::() * count` overflows a usize"); - let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize }; + let diff = src_usize.abs_diff(dst_usize); // If the absolute distance between the ptrs is at least as big as the size of the buffer, // they do not overlap. diff >= size