avoid a negation in is_nonoverlapping

This commit is contained in:
Ralf Jung 2020-02-27 09:45:32 +01:00
parent d1d0de94db
commit 8d3b3063f6

View File

@ -1429,8 +1429,9 @@ pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -
let dst_usize = dst as usize;
let size = mem::size_of::<T>().checked_mul(count).unwrap();
let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
let overlaps = size > diff;
!overlaps
// If the absolute distance between the ptrs is at least as big as the size of the buffer,
// they do not overlap.
diff >= size
}
/// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source