diff --git a/src/libcore/ptr/const_ptr.rs b/src/libcore/ptr/const_ptr.rs index 0e2e6848416b6..e5ac81d8789ec 100644 --- a/src/libcore/ptr/const_ptr.rs +++ b/src/libcore/ptr/const_ptr.rs @@ -295,7 +295,7 @@ impl *const T { intrinsics::ptr_offset_from(self, origin) } - /// Returns whether two pointers are guaranteed equal. + /// Returns whether two pointers are guaranteed to be equal. /// /// At runtime this function behaves like `self == other`. /// However, in some contexts (e.g., compile-time evaluation), @@ -328,7 +328,7 @@ impl *const T { intrinsics::ptr_guaranteed_eq(self, other) } - /// Returns whether two pointers are guaranteed not equal. + /// Returns whether two pointers are guaranteed to be inequal. /// /// At runtime this function behaves like `self != other`. /// However, in some contexts (e.g., compile-time evaluation), diff --git a/src/libcore/ptr/mut_ptr.rs b/src/libcore/ptr/mut_ptr.rs index 67ace1f72a0ab..b8ff5b0dc72cb 100644 --- a/src/libcore/ptr/mut_ptr.rs +++ b/src/libcore/ptr/mut_ptr.rs @@ -273,7 +273,7 @@ impl *mut T { if self.is_null() { None } else { Some(&mut *self) } } - /// Returns whether two pointers are guaranteed equal. + /// Returns whether two pointers are guaranteed to be equal. /// /// At runtime this function behaves like `self == other`. /// However, in some contexts (e.g., compile-time evaluation), @@ -306,7 +306,7 @@ impl *mut T { intrinsics::ptr_guaranteed_eq(self as *const _, other as *const _) } - /// Returns whether two pointers are guaranteed not equal. + /// Returns whether two pointers are guaranteed to be inequal. /// /// At runtime this function behaves like `self != other`. /// However, in some contexts (e.g., compile-time evaluation), diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 12932b06d32d4..c69aafe687cf8 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -5946,8 +5946,7 @@ where } } -// Remove after boostrap bump -#[cfg(bootstrap)] +// Use an equal-pointer optimization when types are `Eq` impl SlicePartialEq for [A] where A: PartialEq + Eq, @@ -5957,47 +5956,14 @@ where return false; } + #[cfg(bootstrap)] if self.as_ptr() == other.as_ptr() { return true; } - self.iter().zip(other.iter()).all(|(x, y)| x == y) - } -} - -// Remove after boostrap bump -#[cfg(bootstrap)] -impl SlicePartialEq for [A] -where - A: PartialEq + BytewiseEquality, -{ - fn equal(&self, other: &[A]) -> bool { - if self.len() != other.len() { - return false; - } - if self.as_ptr() == other.as_ptr() { - return true; - } - unsafe { - let size = mem::size_of_val(self); - memcmp(self.as_ptr() as *const u8, other.as_ptr() as *const u8, size) == 0 - } - } -} - -// Use an equal-pointer optimization when types are `Eq` -#[cfg(not(bootstrap))] -impl SlicePartialEq for [A] -where - A: PartialEq + Eq, -{ - default fn equal(&self, other: &[A]) -> bool { - if self.len() != other.len() { - return false; - } - // While performance would suffer if `guaranteed_eq` just returned `false` // for all arguments, correctness and return value of this function are not affected. + #[cfg(not(bootstrap))] if self.as_ptr().guaranteed_eq(other.as_ptr()) { return true; } @@ -6007,7 +5973,6 @@ where } // Use memcmp for bytewise equality when the types allow -#[cfg(not(bootstrap))] impl SlicePartialEq for [A] where A: PartialEq + BytewiseEquality, @@ -6017,8 +5982,14 @@ where return false; } + #[cfg(bootstrap)] + if self.as_ptr() == other.as_ptr() { + return true; + } + // While performance would suffer if `guaranteed_eq` just returned `false` // for all arguments, correctness and return value of this function are not affected. + #[cfg(not(bootstrap))] if self.as_ptr().guaranteed_eq(other.as_ptr()) { return true; }