Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 20, 2020
1 parent 53686b9 commit 98e97a4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/libcore/ptr/const_ptr.rs
Expand Up @@ -295,7 +295,7 @@ impl<T: ?Sized> *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),
Expand Down Expand Up @@ -328,7 +328,7 @@ impl<T: ?Sized> *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),
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/ptr/mut_ptr.rs
Expand Up @@ -273,7 +273,7 @@ impl<T: ?Sized> *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),
Expand Down Expand Up @@ -306,7 +306,7 @@ impl<T: ?Sized> *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),
Expand Down
47 changes: 9 additions & 38 deletions src/libcore/slice/mod.rs
Expand Up @@ -5946,8 +5946,7 @@ where
}
}

// Remove after boostrap bump
#[cfg(bootstrap)]
// Use an equal-pointer optimization when types are `Eq`
impl<A> SlicePartialEq<A> for [A]
where
A: PartialEq<A> + Eq,
Expand All @@ -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<A> SlicePartialEq<A> for [A]
where
A: PartialEq<A> + 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<A> SlicePartialEq<A> for [A]
where
A: PartialEq<A> + 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;
}
Expand All @@ -6007,7 +5973,6 @@ where
}

// Use memcmp for bytewise equality when the types allow
#[cfg(not(bootstrap))]
impl<A> SlicePartialEq<A> for [A]
where
A: PartialEq<A> + BytewiseEquality,
Expand All @@ -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;
}
Expand Down

0 comments on commit 98e97a4

Please sign in to comment.