optimize Rc<T>::default
This commit is contained in:
parent
1de57a5ce9
commit
5b12d906bb
1 changed files with 10 additions and 1 deletions
|
@ -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(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue