mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Short-circuit Rc/Arc equality checking on equal pointers where T: Eq
Closes #42655
This commit is contained in:
parent
9772d02774
commit
2a916a617f
@ -8,6 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(specialization)]
|
||||
#![allow(deprecated)]
|
||||
|
||||
//! Single-threaded reference-counting pointers. 'Rc' stands for 'Reference
|
||||
@ -906,6 +907,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
|
||||
///
|
||||
/// Two `Rc`s are equal if their inner values are equal.
|
||||
///
|
||||
/// If `T` also implements `Eq`, two `Rc`s that point to the same value are
|
||||
/// always equal.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -916,7 +920,7 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
|
||||
/// assert!(five == Rc::new(5));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &Rc<T>) -> bool {
|
||||
default fn eq(&self, other: &Rc<T>) -> bool {
|
||||
**self == **other
|
||||
}
|
||||
|
||||
@ -924,6 +928,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
|
||||
///
|
||||
/// Two `Rc`s are unequal if their inner values are unequal.
|
||||
///
|
||||
/// If `T` also implements `Eq`, two `Rc`s that point to the same value are
|
||||
/// never unequal.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -934,11 +941,25 @@ impl<T: ?Sized + PartialEq> PartialEq for Rc<T> {
|
||||
/// assert!(five != Rc::new(6));
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: &Rc<T>) -> bool {
|
||||
default fn ne(&self, other: &Rc<T>) -> bool {
|
||||
**self != **other
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized + Eq> PartialEq for Rc<T> {
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &Rc<T>) -> bool {
|
||||
Rc::ptr_eq(self, other) || **self == **other
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: &Rc<T>) -> bool {
|
||||
!Rc::ptr_eq(self, other) && **self != **other
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized + Eq> Eq for Rc<T> {}
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(specialization)]
|
||||
#![stable(feature = "rust1", since = "1.0.0")]
|
||||
|
||||
//! Thread-safe reference-counting pointers.
|
||||
@ -1293,6 +1294,9 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
|
||||
///
|
||||
/// Two `Arc`s are equal if their inner values are equal.
|
||||
///
|
||||
/// If `T` also implements `Eq`, two `Arc`s that point to the same value are
|
||||
/// always equal.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -1302,14 +1306,17 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
|
||||
///
|
||||
/// assert!(five == Arc::new(5));
|
||||
/// ```
|
||||
fn eq(&self, other: &Arc<T>) -> bool {
|
||||
*(*self) == *(*other)
|
||||
default fn eq(&self, other: &Arc<T>) -> bool {
|
||||
**self == **other
|
||||
}
|
||||
|
||||
/// Inequality for two `Arc`s.
|
||||
///
|
||||
/// Two `Arc`s are unequal if their inner values are unequal.
|
||||
///
|
||||
/// If `T` also implements `Eq`, two `Arc`s that point to the same value are
|
||||
/// never unequal.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -1319,8 +1326,21 @@ impl<T: ?Sized + PartialEq> PartialEq for Arc<T> {
|
||||
///
|
||||
/// assert!(five != Arc::new(6));
|
||||
/// ```
|
||||
default fn ne(&self, other: &Arc<T>) -> bool {
|
||||
**self != **other
|
||||
}
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized + Eq> PartialEq for Arc<T> {
|
||||
#[inline(always)]
|
||||
fn eq(&self, other: &Arc<T>) -> bool {
|
||||
Arc::ptr_eq(self, other) || **self == **other
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn ne(&self, other: &Arc<T>) -> bool {
|
||||
*(*self) != *(*other)
|
||||
!Arc::ptr_eq(self, other) && **self != **other
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
Loading…
Reference in New Issue
Block a user