From f6023a01d43557b45dda550ef50d689877b87226 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 25 May 2013 08:40:02 -0400 Subject: use uninit for cast::transmute_copy --- src/libstd/cast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libstd/cast.rs') diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs index cde22afd34a..d4a87f562e1 100644 --- a/src/libstd/cast.rs +++ b/src/libstd/cast.rs @@ -15,7 +15,7 @@ use unstable::intrinsics; /// Casts the value at `src` to U. The two types must have the same length. pub unsafe fn transmute_copy(src: &T) -> U { - let mut dest: U = intrinsics::init(); + let mut dest: U = intrinsics::uninit(); { let dest_ptr: *mut u8 = transmute(&mut dest); let src_ptr: *u8 = transmute(src); -- cgit 1.4.1-3-g733a5 From b25c5201028d7e08ef6c40385fd848157ea72567 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 25 May 2013 11:43:11 -0400 Subject: make transmute_copy use memcpy, and inline it --- src/libstd/cast.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/libstd/cast.rs') 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(src: &T) -> U { let mut dest: U = intrinsics::uninit(); { @@ -26,6 +27,26 @@ pub unsafe fn transmute_copy(src: &T) -> U { dest } +#[cfg(target_word_size = "32", not(stage0))] +#[inline(always)] +pub unsafe fn transmute_copy(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::() as u64); + dest +} + +#[cfg(target_word_size = "64", not(stage0))] +#[inline(always)] +pub unsafe fn transmute_copy(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::() as u64); + dest +} + /** * Move a thing into the void * -- cgit 1.4.1-3-g733a5 From 14846613bbd72003dd8f244b64ad679b586b6dd9 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 25 May 2013 11:47:11 -0400 Subject: inline bump_box_refcount --- src/libstd/cast.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/libstd/cast.rs') diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs index 40a62c12bb3..9ef5d8ad6f7 100644 --- a/src/libstd/cast.rs +++ b/src/libstd/cast.rs @@ -64,6 +64,7 @@ pub unsafe fn forget(thing: T) { intrinsics::forget(thing); } * and/or reinterpret_cast when such calls would otherwise scramble a box's * reference count */ +#[inline(always)] pub unsafe fn bump_box_refcount(t: @T) { forget(t); } /** -- cgit 1.4.1-3-g733a5 From e6c04dea0325af808198306e283c17f90d31fc26 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Mon, 27 May 2013 18:14:00 -0400 Subject: fix casts on 32-bit --- src/libstd/cast.rs | 2 +- src/libstd/ptr.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd/cast.rs') diff --git a/src/libstd/cast.rs b/src/libstd/cast.rs index 9ef5d8ad6f7..30ad41f0ca2 100644 --- a/src/libstd/cast.rs +++ b/src/libstd/cast.rs @@ -33,7 +33,7 @@ pub unsafe fn transmute_copy(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::() as u64); + intrinsics::memcpy32(dest_ptr, src_ptr, sys::size_of::() as u32); dest } diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index e787558c6e4..309129b7f13 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -109,7 +109,7 @@ pub unsafe fn copy_memory(dst: *mut T, src: *const T, count: uint) { #[cfg(target_word_size = "32", not(stage0))] pub unsafe fn copy_memory(dst: *mut T, src: *const T, count: uint) { use unstable::intrinsics::memmove32; - memmove32(dst, src, count as u32); + memmove32(dst, src as *T, count as u32); } #[inline(always)] -- cgit 1.4.1-3-g733a5