Skip to content

Commit e19ad45

Browse files
authored
Rollup merge of #60727 - chpio:master, r=sfackler
add comment to `Rc`/`Arc`'s `Eq` specialization in addition to #56550 #42965 (comment)
2 parents 5da009e + 740a8da commit e19ad45

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/liballoc/rc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,11 @@ impl<T: ?Sized + PartialEq> RcEqIdent<T> for Rc<T> {
932932
}
933933
}
934934

935+
/// We're doing this specialization here, and not as a more general optimization on `&T`, because it
936+
/// would otherwise add a cost to all equality checks on refs. We assume that `Rc`s are used to
937+
/// store large values, that are slow to clone, but also heavy to check for equality, causing this
938+
/// cost to pay off more easily. It's also more likely to have two `Rc` clones, that point to
939+
/// the same value, than two `&T`s.
935940
#[stable(feature = "rust1", since = "1.0.0")]
936941
impl<T: ?Sized + Eq> RcEqIdent<T> for Rc<T> {
937942
#[inline]

src/liballoc/sync.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,11 @@ impl<T: ?Sized + PartialEq> ArcEqIdent<T> for Arc<T> {
13771377
}
13781378
}
13791379

1380+
/// We're doing this specialization here, and not as a more general optimization on `&T`, because it
1381+
/// would otherwise add a cost to all equality checks on refs. We assume that `Arc`s are used to
1382+
/// store large values, that are slow to clone, but also heavy to check for equality, causing this
1383+
/// cost to pay off more easily. It's also more likely to have two `Arc` clones, that point to
1384+
/// the same value, than two `&T`s.
13801385
#[stable(feature = "rust1", since = "1.0.0")]
13811386
impl<T: ?Sized + Eq> ArcEqIdent<T> for Arc<T> {
13821387
#[inline]

0 commit comments

Comments
 (0)