Add a bunch of inline hints.

This commit is contained in:
Graydon Hoare 2012-09-11 15:57:32 -07:00
parent 3c14dae4a6
commit 4ce2ee12be
3 changed files with 12 additions and 0 deletions

View File

@ -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
* performing dark magick.
*/
#[inline(always)]
pure fn get_type_desc<T>() -> *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)
#[inline(always)]
pure fn refcount<T>(+t: @T) -> uint {
unsafe {
let ref_ptr: *uint = unsafe::reinterpret_cast(&t);

View File

@ -51,6 +51,7 @@ unsafe fn bump_box_refcount<T>(+t: @T) { forget(move t); }
*
* assert transmute("L") == ~[76u8, 0u8];
*/
#[inline(always)]
unsafe fn transmute<L, G>(-thing: L) -> G {
debug!(">>> in transmute! <<<");
debug!("transmute 1: %?", &thing);
@ -61,26 +62,33 @@ unsafe fn transmute<L, G>(-thing: L) -> G {
}
/// Coerce an immutable reference to be mutable.
#[inline(always)]
unsafe fn transmute_mut<T>(+ptr: &a/T) -> &a/mut T { transmute(move ptr) }
/// Coerce a mutable reference to be immutable.
#[inline(always)]
unsafe fn transmute_immut<T>(+ptr: &a/mut T) -> &a/T { transmute(move ptr) }
/// 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) }
/// Coerce an immutable reference to be mutable.
#[inline(always)]
unsafe fn transmute_mut_unsafe<T>(+ptr: *const T) -> *mut T { transmute(ptr) }
/// Coerce an immutable reference to be mutable.
#[inline(always)]
unsafe fn transmute_immut_unsafe<T>(+ptr: *const T) -> *T { transmute(ptr) }
/// 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 {
transmute(move ptr)
}
/// 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 {
transmute_region(ptr)
}

View File

@ -9,9 +9,11 @@ use cmp::Eq;
*/
/// The identity function.
#[inline(always)]
pure fn id<T>(+x: T) -> T { move x }
/// Ignores a value.
#[inline(always)]
pure fn ignore<T>(+_x: T) { }
/// Sets `*ptr` to `new_value`, invokes `op()`, and then restores the