Skip to content

Commit 5733726

Browse files
committed
A better core::mem::dropped implementation suggested by huonw on the PR.
1 parent 5bc35b1 commit 5733726

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/libcore/mem.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ pub unsafe fn zeroed<T>() -> T {
173173
#[inline]
174174
#[unstable(feature = "filling_drop")]
175175
pub unsafe fn dropped<T>() -> T {
176-
let mut x: T = uninitialized();
177-
let p: *mut u8 = transmute(&mut x as *mut T);
178-
for i in 0..size_of::<T>() {
179-
*p.offset(i as isize) = POST_DROP_U8;
180-
}
181-
x
176+
#[cfg(stage0)]
177+
#[inline(always)]
178+
unsafe fn dropped_impl<T>() -> T { zeroed() }
179+
180+
#[cfg(not(stage0))]
181+
#[inline(always)]
182+
unsafe fn dropped_impl<T>() -> T { intrinsics::init_dropped() }
183+
184+
dropped_impl()
182185
}
183186

184187
/// Create an uninitialized value.

0 commit comments

Comments
 (0)