Skip to content

Commit bc84ec6

Browse files
committed
Make Rc<T>::deref zero-cost
1 parent 369a658 commit bc84ec6

File tree

10 files changed

+1380
-628
lines changed

10 files changed

+1380
-628
lines changed

library/alloc/src/raw_rc/raw_rc.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,6 @@ where
225225
self.weak.into_raw_parts()
226226
}
227227

228-
// `is_unique` only exists on `Arc`, so we need this `#[cfg(not(no_sync))]`. It can be removed
229-
// if `Rc::is_unique` is added.
230-
#[cfg(not(no_sync))]
231-
pub(crate) unsafe fn is_unique<R>(&self) -> bool
232-
where
233-
R: RcOps,
234-
{
235-
unsafe { is_unique::<R>(self.weak.as_ptr().cast()) }
236-
}
237-
238228
#[cfg(not(no_global_oom_handling))]
239229
pub(crate) unsafe fn make_mut<R>(&mut self) -> &mut T
240230
where
@@ -720,23 +710,6 @@ impl<A> RawRc<dyn Any, A> {
720710
}
721711
}
722712

723-
#[cfg(not(no_sync))]
724-
impl<A> RawRc<dyn Any + Send + Sync, A> {
725-
pub(crate) fn downcast<T>(self) -> Result<RawRc<T, A>, Self>
726-
where
727-
T: Any,
728-
{
729-
if self.as_ref().is::<T>() { Ok(unsafe { self.downcast_unchecked() }) } else { Err(self) }
730-
}
731-
732-
pub(crate) unsafe fn downcast_unchecked<T>(self) -> RawRc<T, A>
733-
where
734-
T: Any,
735-
{
736-
unsafe { self.cast() }
737-
}
738-
}
739-
740713
impl<T, A> AsRef<T> for RawRc<T, A>
741714
where
742715
T: ?Sized,

library/alloc/src/raw_rc/raw_weak.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,13 @@ where
283283
!ptr::addr_eq(self.ptr.as_ptr(), other.ptr.as_ptr())
284284
}
285285

286-
/// Returns the `RefCounts` object inside the reference-counted allocation if `self` is
287-
/// non-dangling.
288-
#[cfg(not(no_sync))]
289-
pub(crate) fn ref_counts(&self) -> Option<&RefCounts> {
290-
(!is_dangling(self.ptr.cast())).then(|| unsafe { self.ref_counts_unchecked() })
291-
}
292-
293286
/// Returns the `RefCounts` object inside the reference-counted allocation, assume `self` is
294287
/// non-dangling.
295288
///
296289
/// # Safety
297290
///
298291
/// `self` is non-dangling.
292+
#[cfg(not(no_global_oom_handling))]
299293
pub(super) unsafe fn ref_counts_unchecked(&self) -> &RefCounts {
300294
unsafe { super::ref_counts_ptr_from_value_ptr(self.ptr.cast()).as_ref() }
301295
}

0 commit comments

Comments
 (0)