optimize Rc<T>::default
· qinheping/verify-rust-std@fe5101d (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
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 |