about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2015-03-23 23:52:21 +0100
committerFelix S. Klock II <pnkfelix@pnkfx.org>2015-03-26 14:08:55 +0100
commit5733726508bbfddebf1024e41b2d34439d548bdb (patch)
tree50c313f06294e7aced0284b9746071985726e79c /src
parent5bc35b1852ea3b7871befeeeec7531107e147278 (diff)
downloadrust-5733726508bbfddebf1024e41b2d34439d548bdb.tar.gz
rust-5733726508bbfddebf1024e41b2d34439d548bdb.zip
A better `core::mem::dropped` implementation suggested by huonw on the PR.
Diffstat (limited to 'src')
-rw-r--r--src/libcore/mem.rs15
1 files changed, 9 insertions, 6 deletions
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>() -> T {
 #[inline]
 #[unstable(feature = "filling_drop")]
 pub unsafe fn dropped<T>() -> T {
-    let mut x: T = uninitialized();
-    let p: *mut u8 = transmute(&mut x as *mut T);
-    for i in 0..size_of::<T>() {
-        *p.offset(i as isize) = POST_DROP_U8;
-    }
-    x
+    #[cfg(stage0)]
+    #[inline(always)]
+    unsafe fn dropped_impl<T>() -> T { zeroed() }
+
+    #[cfg(not(stage0))]
+    #[inline(always)]
+    unsafe fn dropped_impl<T>() -> T { intrinsics::init_dropped() }
+
+    dropped_impl()
 }
 
 /// Create an uninitialized value.