Skip to content

Commit

Permalink
avoid a negation in is_nonoverlapping
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Feb 27, 2020
1 parent d1d0de9 commit 8d3b306
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d3b306

Please sign in to comment.