mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Add a bunch of inline hints.
This commit is contained in:
parent
3c14dae4a6
commit
4ce2ee12be
@ -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);
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user