From d1c6e34e1c633159d50187c3e3cf65547d9b8cb7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 6 Mar 2012 11:20:43 -0800 Subject: [PATCH] core: Inline a bunch of unsafe functions --- src/libcore/ptr.rs | 6 ++++++ src/libcore/unsafe.rs | 2 ++ 2 files changed, 8 insertions(+) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index d6dda41c3a4..636a076abb9 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -16,6 +16,7 @@ Function: addr_of Get an unsafe pointer to a value */ +#[inline(always)] fn addr_of(val: T) -> *T { ret rusti::addr_of(val); } /* @@ -23,6 +24,7 @@ Function: mut_addr_of Get an unsafe mutable pointer to a value */ +#[inline(always)] fn mut_addr_of(val: T) -> *mutable T unsafe { ret unsafe::reinterpret_cast(rusti::addr_of(val)); } @@ -42,6 +44,7 @@ Function: mut_offset Calculate the offset from a mutable pointer */ +#[inline(always)] fn mut_offset(ptr: *mutable T, count: uint) -> *mutable T { ret rusti::ptr_offset(ptr as *T, count) as *mutable T; } @@ -52,6 +55,7 @@ Function: null Create an unsafe null pointer */ +#[inline(always)] fn null() -> *T unsafe { ret unsafe::reinterpret_cast(0u); } /* @@ -60,6 +64,7 @@ Function: memcpy Copies data from one src to dst that is not overlapping each other. Count is the number of elements to copy and not the number of bytes. */ +#[inline(always)] unsafe fn memcpy(dst: *T, src: *T, count: uint) { rusti::memcpy(dst, src, count); } @@ -70,6 +75,7 @@ Function: memmove Copies data from one src to dst, overlap between the two pointers may occur. Count is the number of elements to copy and not the number of bytes. */ +#[inline(always)] unsafe fn memmove(dst: *T, src: *T, count: uint) { rusti::memmove(dst, src, count); } diff --git a/src/libcore/unsafe.rs b/src/libcore/unsafe.rs index b534d8264a6..d3d2f4ee088 100644 --- a/src/libcore/unsafe.rs +++ b/src/libcore/unsafe.rs @@ -17,6 +17,7 @@ Function: reinterpret_cast Casts the value at `src` to U. The two types must have the same length. */ +#[inline(always)] unsafe fn reinterpret_cast(src: T) -> U { let t1 = sys::get_type_desc::(); let t2 = sys::get_type_desc::(); @@ -36,6 +37,7 @@ to run any required cleanup or memory-management operations on it. This can be used for various acts of magick, particularly when using reinterpret_cast on managed pointer types. */ +#[inline(always)] unsafe fn leak(-thing: T) { rusti::leak(thing); } #[cfg(test)]