|
56 | 56 |
|
57 | 57 | use crate::marker::DiscriminantKind;
|
58 | 58 | use crate::marker::Tuple;
|
59 |
| -use crate::mem::{self, align_of}; |
| 59 | +use crate::mem::align_of; |
60 | 60 |
|
61 | 61 | pub mod mir;
|
62 | 62 | pub mod simd;
|
@@ -2659,33 +2659,12 @@ pub(crate) fn is_valid_allocation_size(size: usize, len: usize) -> bool {
|
2659 | 2659 | len <= max_len
|
2660 | 2660 | }
|
2661 | 2661 |
|
2662 |
| -pub(crate) fn is_nonoverlapping_mono( |
2663 |
| - src: *const (), |
2664 |
| - dst: *const (), |
2665 |
| - size: usize, |
2666 |
| - count: usize, |
2667 |
| -) -> bool { |
2668 |
| - let src_usize = src.addr(); |
2669 |
| - let dst_usize = dst.addr(); |
2670 |
| - let Some(size) = size.checked_mul(count) else { |
2671 |
| - crate::panicking::panic_nounwind( |
2672 |
| - "is_nonoverlapping: `size_of::<T>() * count` overflows a usize", |
2673 |
| - ) |
2674 |
| - }; |
2675 |
| - let diff = src_usize.abs_diff(dst_usize); |
2676 |
| - // If the absolute distance between the ptrs is at least as big as the size of the buffer, |
2677 |
| - // they do not overlap. |
2678 |
| - diff >= size |
2679 |
| -} |
2680 |
| - |
2681 | 2662 | /// Checks whether the regions of memory starting at `src` and `dst` of size
|
2682 |
| -/// `count * size_of::<T>()` do *not* overlap. |
2683 |
| -#[inline] |
2684 |
| -pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool { |
| 2663 | +/// `count * size` do *not* overlap. |
| 2664 | +pub(crate) fn is_nonoverlapping(src: *const (), dst: *const (), size: usize, count: usize) -> bool { |
2685 | 2665 | let src_usize = src.addr();
|
2686 | 2666 | let dst_usize = dst.addr();
|
2687 |
| - let Some(size) = mem::size_of::<T>().checked_mul(count) else { |
2688 |
| - // Use panic_nounwind instead of Option::expect, so that this function is nounwind. |
| 2667 | + let Some(size) = size.checked_mul(count) else { |
2689 | 2668 | crate::panicking::panic_nounwind(
|
2690 | 2669 | "is_nonoverlapping: `size_of::<T>() * count` overflows a usize",
|
2691 | 2670 | )
|
@@ -2809,7 +2788,7 @@ pub const unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: us
|
2809 | 2788 | ) =>
|
2810 | 2789 | is_aligned_and_not_null(src, align)
|
2811 | 2790 | && is_aligned_and_not_null(dst, align)
|
2812 |
| - && is_nonoverlapping_mono(src, dst, size, count) |
| 2791 | + && is_nonoverlapping(src, dst, size, count) |
2813 | 2792 | );
|
2814 | 2793 | copy_nonoverlapping(src, dst, count)
|
2815 | 2794 | }
|
|
0 commit comments