From 5733726508bbfddebf1024e41b2d34439d548bdb Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Mon, 23 Mar 2015 23:52:21 +0100 Subject: A better `core::mem::dropped` implementation suggested by huonw on the PR. --- src/libcore/mem.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/libcore') diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index 7fea029e02d..4b9e070619f 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -173,12 +173,15 @@ pub unsafe fn zeroed() -> T { #[inline] #[unstable(feature = "filling_drop")] pub unsafe fn dropped() -> T { - let mut x: T = uninitialized(); - let p: *mut u8 = transmute(&mut x as *mut T); - for i in 0..size_of::() { - *p.offset(i as isize) = POST_DROP_U8; - } - x + #[cfg(stage0)] + #[inline(always)] + unsafe fn dropped_impl() -> T { zeroed() } + + #[cfg(not(stage0))] + #[inline(always)] + unsafe fn dropped_impl() -> T { intrinsics::init_dropped() } + + dropped_impl() } /// Create an uninitialized value. -- cgit 1.4.1-3-g733a5