Skip to content

Commit

Permalink
optimize Rc<T>::default
Browse files Browse the repository at this point in the history
  • Loading branch information
slanterns committed Oct 22, 2024
1 parent 2e8dd5b commit fe5101d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,16 @@ impl<T: Default> Default for Rc<T> {
/// ```
#[inline]
fn default() -> Rc<T> {
Rc::new(Default::default())
unsafe {
Self::from_inner(
Box::leak(Box::write(Box::new_uninit(), RcInner {
strong: Cell::new(1),
weak: Cell::new(1),
value: T::default(),
}))
.into(),
)
}
}
}

Expand Down

0 comments on commit fe5101d

Please sign in to comment.