Skip to content

Commit b729368

Browse files
committed
Address review comments
1 parent bb57c9f commit b729368

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

library/alloc/src/rc.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Rc<U>> for Rc<T> {}
295295
impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Rc<U>> for Rc<T> {}
296296

297297
impl<T: ?Sized> Rc<T> {
298+
#[inline(always)]
299+
fn inner(&self) -> &RcBox<T> {
300+
// This unsafety is ok because while this Rc is alive we're guaranteed
301+
// that the inner pointer is valid.
302+
unsafe { self.ptr.as_ref() }
303+
}
304+
298305
fn from_inner(ptr: NonNull<RcBox<T>>) -> Self {
299306
Self { ptr, phantom: PhantomData }
300307
}
@@ -845,17 +852,10 @@ impl<T: ?Sized> Rc<T> {
845852
#[unstable(feature = "get_mut_unchecked", issue = "63292")]
846853
pub unsafe fn get_mut_unchecked(this: &mut Self) -> &mut T {
847854
// We are careful to *not* create a reference covering the "count" fields, as
848-
// this would alias with concurrent access to the reference counts (e.g. by `Weak`).
855+
// this would conflict with accesses to the reference counts (e.g. by `Weak`).
849856
unsafe { &mut (*this.ptr.as_ptr()).value }
850857
}
851858

852-
#[inline]
853-
fn inner(&self) -> &RcBox<T> {
854-
// This unsafety is ok because while this Rc is alive we're guaranteed
855-
// that the inner pointer is valid.
856-
unsafe { self.ptr.as_ref() }
857-
}
858-
859859
#[inline]
860860
#[stable(feature = "ptr_eq", since = "1.17.0")]
861861
/// Returns `true` if the two `Rc`s point to the same allocation
@@ -2145,18 +2145,24 @@ trait RcInnerPtr {
21452145
}
21462146

21472147
impl<T: ?Sized> RcInnerPtr for RcBox<T> {
2148+
#[inline(always)]
21482149
fn weak_ref(&self) -> &Cell<usize> {
21492150
&self.weak
21502151
}
2152+
2153+
#[inline(always)]
21512154
fn strong_ref(&self) -> &Cell<usize> {
21522155
&self.strong
21532156
}
21542157
}
21552158

21562159
impl<'a> RcInnerPtr for WeakInner<'a> {
2160+
#[inline(always)]
21572161
fn weak_ref(&self) -> &Cell<usize> {
21582162
self.weak
21592163
}
2164+
2165+
#[inline(always)]
21602166
fn strong_ref(&self) -> &Cell<usize> {
21612167
self.strong
21622168
}

0 commit comments

Comments
 (0)