|
1 | 1 | //! Comparison traits for `[T]`. |
2 | 2 |
|
3 | | -use crate::cmp::{self, BytewiseEq, Ordering}; |
| 3 | +use crate::cmp::{self, Ordering}; |
4 | 4 | use crate::ffi; |
5 | | -use crate::mem; |
6 | 5 |
|
7 | 6 | use super::from_raw_parts; |
8 | 7 | use super::memchr; |
@@ -92,20 +91,28 @@ where |
92 | 91 | } |
93 | 92 |
|
94 | 93 | // Use memcmp for bytewise equality when the types allow |
95 | | -impl<A, B> SlicePartialEq<B> for [A] |
96 | | -where |
97 | | - A: BytewiseEq<B>, |
98 | | -{ |
99 | | - fn equal(&self, other: &[B]) -> bool { |
100 | | - if self.len() != other.len() { |
101 | | - return false; |
102 | | - } |
| 94 | +// and `memcmp` is not equivalent to our generic case |
| 95 | +#[cfg(not(target_env = "musl"))] |
| 96 | +mod bytewise_memcmp { |
| 97 | + use super::{memcmp, SlicePartialEq}; |
| 98 | + use crate::cmp::BytewiseEq; |
| 99 | + use crate::mem; |
| 100 | + |
| 101 | + impl<A, B> SlicePartialEq<B> for [A] |
| 102 | + where |
| 103 | + A: BytewiseEq<B>, |
| 104 | + { |
| 105 | + fn equal(&self, other: &[B]) -> bool { |
| 106 | + if self.len() != other.len() { |
| 107 | + return false; |
| 108 | + } |
103 | 109 |
|
104 | | - // SAFETY: `self` and `other` are references and are thus guaranteed to be valid. |
105 | | - // The two slices have been checked to have the same size above. |
106 | | - unsafe { |
107 | | - let size = mem::size_of_val(self); |
108 | | - memcmp(self.as_ptr() as *const u8, other.as_ptr() as *const u8, size) == 0 |
| 110 | + // SAFETY: `self` and `other` are references and are thus guaranteed to be valid. |
| 111 | + // The two slices have been checked to have the same size above. |
| 112 | + unsafe { |
| 113 | + let size = mem::size_of_val(self); |
| 114 | + memcmp(self.as_ptr() as *const u8, other.as_ptr() as *const u8, size) == 0 |
| 115 | + } |
109 | 116 | } |
110 | 117 | } |
111 | 118 | } |
|
0 commit comments