about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorDaniel Micay <danielmicay@gmail.com>2013-05-25 11:43:11 -0400
committerDaniel Micay <danielmicay@gmail.com>2013-05-26 10:26:04 -0400
commitb25c5201028d7e08ef6c40385fd848157ea72567 (patch)
tree23b8bffc18c561694ec4a50be8fbd504255fe61b /src/libstd
parent58d6864ad700d9972b57824eed758c9b71e465d8 (diff)
downloadrust-b25c5201028d7e08ef6c40385fd848157ea72567.tar.gz
rust-b25c5201028d7e08ef6c40385fd848157ea72567.zip
make transmute_copy use memcpy, and inline it
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/cast.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs
index d4a87f562e1..40a62c12bb3 100644
--- a/src/libstd/cast.rs
+++ b/src/libstd/cast.rs
@@ -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
  *