make transmute_copy use memcpy, and inline it
This commit is contained in:
parent
58d6864ad7
commit
b25c520102
1 changed files with 21 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ use sys;
|
|||
use unstable::intrinsics;
|
||||
|
||||
/// Casts the value at `src` to U. The two types must have the same length.
|
||||
#[cfg(stage0)]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
let mut dest: U = intrinsics::uninit();
|
||||
{
|
||||
|
|
@ -26,6 +27,26 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
|||
dest
|
||||
}
|
||||
|
||||
#[cfg(target_word_size = "32", not(stage0))]
|
||||
#[inline(always)]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
let mut dest: U = intrinsics::uninit();
|
||||
let dest_ptr: *mut u8 = transmute(&mut dest);
|
||||
let src_ptr: *u8 = transmute(src);
|
||||
intrinsics::memcpy32(dest_ptr, src_ptr, sys::size_of::<U>() as u64);
|
||||
dest
|
||||
}
|
||||
|
||||
#[cfg(target_word_size = "64", not(stage0))]
|
||||
#[inline(always)]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
let mut dest: U = intrinsics::uninit();
|
||||
let dest_ptr: *mut u8 = transmute(&mut dest);
|
||||
let src_ptr: *u8 = transmute(src);
|
||||
intrinsics::memcpy64(dest_ptr, src_ptr, sys::size_of::<U>() as u64);
|
||||
dest
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a thing into the void
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue