core: Inline a bunch of unsafe functions

This commit is contained in:
Brian Anderson 2012-03-06 11:20:43 -08:00
parent 712dd23541
commit d1c6e34e1c
2 changed files with 8 additions and 0 deletions

View File

@ -16,6 +16,7 @@ Function: addr_of
Get an unsafe pointer to a value
*/
#[inline(always)]
fn addr_of<T>(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<T>(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<T>(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>() -> *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<T>(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<T>(dst: *T, src: *T, count: uint) {
rusti::memmove(dst, src, count);
}

View File

@ -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<T, U>(src: T) -> U {
let t1 = sys::get_type_desc::<T>();
let t2 = sys::get_type_desc::<U>();
@ -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<T>(-thing: T) { rusti::leak(thing); }
#[cfg(test)]