optimize Rc<T>::default · qinheping/verify-rust-std@fe5101d (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Commit fe5101d

File tree

1 file changed

lines changed

1 file changed

lines changed

Lines changed: 10 additions & 1 deletion

Original file line number Diff line number Diff line change
@@ -2312,7 +2312,16 @@ impl<T: Default> Default for Rc {
2312 2312 /// ```
2313 2313 #[inline]
2314 2314 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 +}
2316 2325 }
2317 2326 }
2318 2327