Skip to content

Commit fe5101d

Browse files
committed
optimize Rc<T>::default
1 parent 2e8dd5b commit fe5101d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

alloc/src/rc.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2312,7 +2312,16 @@ impl<T: Default> Default for Rc<T> {
23122312
/// ```
23132313
#[inline]
23142314
fn default() -> Rc<T> {
2315-
Rc::new(Default::default())
2315+
unsafe {
2316+
Self::from_inner(
2317+
Box::leak(Box::write(Box::new_uninit(), RcInner {
2318+
strong: Cell::new(1),
2319+
weak: Cell::new(1),
2320+
value: T::default(),
2321+
}))
2322+
.into(),
2323+
)
2324+
}
23162325
}
23172326
}
23182327

0 commit comments

Comments
 (0)