Add a bunch of inline hints.
This commit is contained in:
@@ -65,6 +65,7 @@ pure fn shape_le<T:Ord>(x1: &T, x2: &T) -> bool {
|
|||||||
* Useful for calling certain function in the Rust runtime or otherwise
|
* Useful for calling certain function in the Rust runtime or otherwise
|
||||||
* performing dark magick.
|
* performing dark magick.
|
||||||
*/
|
*/
|
||||||
|
#[inline(always)]
|
||||||
pure fn get_type_desc<T>() -> *TypeDesc {
|
pure fn get_type_desc<T>() -> *TypeDesc {
|
||||||
unchecked { rusti::get_tydesc::<T>() as *TypeDesc }
|
unchecked { rusti::get_tydesc::<T>() as *TypeDesc }
|
||||||
}
|
}
|
||||||
@@ -93,6 +94,7 @@ pure fn pref_align_of<T>() -> uint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the refcount of a shared box (as just before calling this)
|
/// Returns the refcount of a shared box (as just before calling this)
|
||||||
|
#[inline(always)]
|
||||||
pure fn refcount<T>(+t: @T) -> uint {
|
pure fn refcount<T>(+t: @T) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ref_ptr: *uint = unsafe::reinterpret_cast(&t);
|
let ref_ptr: *uint = unsafe::reinterpret_cast(&t);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ unsafe fn bump_box_refcount<T>(+t: @T) { forget(move t); }
|
|||||||
*
|
*
|
||||||
* assert transmute("L") == ~[76u8, 0u8];
|
* assert transmute("L") == ~[76u8, 0u8];
|
||||||
*/
|
*/
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute<L, G>(-thing: L) -> G {
|
unsafe fn transmute<L, G>(-thing: L) -> G {
|
||||||
debug!(">>> in transmute! <<<");
|
debug!(">>> in transmute! <<<");
|
||||||
debug!("transmute 1: %?", &thing);
|
debug!("transmute 1: %?", &thing);
|
||||||
@@ -61,26 +62,33 @@ unsafe fn transmute<L, G>(-thing: L) -> G {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Coerce an immutable reference to be mutable.
|
/// Coerce an immutable reference to be mutable.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_mut<T>(+ptr: &a/T) -> &a/mut T { transmute(move ptr) }
|
unsafe fn transmute_mut<T>(+ptr: &a/T) -> &a/mut T { transmute(move ptr) }
|
||||||
|
|
||||||
/// Coerce a mutable reference to be immutable.
|
/// Coerce a mutable reference to be immutable.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_immut<T>(+ptr: &a/mut T) -> &a/T { transmute(move ptr) }
|
unsafe fn transmute_immut<T>(+ptr: &a/mut T) -> &a/T { transmute(move ptr) }
|
||||||
|
|
||||||
/// Coerce a borrowed pointer to have an arbitrary associated region.
|
/// Coerce a borrowed pointer to have an arbitrary associated region.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_region<T>(+ptr: &a/T) -> &b/T { transmute(move ptr) }
|
unsafe fn transmute_region<T>(+ptr: &a/T) -> &b/T { transmute(move ptr) }
|
||||||
|
|
||||||
/// Coerce an immutable reference to be mutable.
|
/// Coerce an immutable reference to be mutable.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_mut_unsafe<T>(+ptr: *const T) -> *mut T { transmute(ptr) }
|
unsafe fn transmute_mut_unsafe<T>(+ptr: *const T) -> *mut T { transmute(ptr) }
|
||||||
|
|
||||||
/// Coerce an immutable reference to be mutable.
|
/// Coerce an immutable reference to be mutable.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_immut_unsafe<T>(+ptr: *const T) -> *T { transmute(ptr) }
|
unsafe fn transmute_immut_unsafe<T>(+ptr: *const T) -> *T { transmute(ptr) }
|
||||||
|
|
||||||
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
|
/// Coerce a borrowed mutable pointer to have an arbitrary associated region.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn transmute_mut_region<T>(+ptr: &a/mut T) -> &b/mut T {
|
unsafe fn transmute_mut_region<T>(+ptr: &a/mut T) -> &b/mut T {
|
||||||
transmute(move ptr)
|
transmute(move ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transforms lifetime of the second pointer to match the first.
|
/// Transforms lifetime of the second pointer to match the first.
|
||||||
|
#[inline(always)]
|
||||||
unsafe fn copy_lifetime<S,T>(_ptr: &a/S, ptr: &T) -> &a/T {
|
unsafe fn copy_lifetime<S,T>(_ptr: &a/S, ptr: &T) -> &a/T {
|
||||||
transmute_region(ptr)
|
transmute_region(ptr)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ use cmp::Eq;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/// The identity function.
|
/// The identity function.
|
||||||
|
#[inline(always)]
|
||||||
pure fn id<T>(+x: T) -> T { move x }
|
pure fn id<T>(+x: T) -> T { move x }
|
||||||
|
|
||||||
/// Ignores a value.
|
/// Ignores a value.
|
||||||
|
#[inline(always)]
|
||||||
pure fn ignore<T>(+_x: T) { }
|
pure fn ignore<T>(+_x: T) { }
|
||||||
|
|
||||||
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the
|
||||||
|
|||||||
Reference in New Issue
Block a user