Add #[inline(never)], and also fixed inlining on vec::push
This commit is contained in:
committed by
Paul Stansifer
parent
f4c093c4af
commit
0a8b794a3a
@@ -108,6 +108,11 @@ impl private_methods<A> for dvec<A> {
|
|||||||
// almost nothing works without the copy bound due to limitations
|
// almost nothing works without the copy bound due to limitations
|
||||||
// around closures.
|
// around closures.
|
||||||
impl extensions<A> for dvec<A> {
|
impl extensions<A> for dvec<A> {
|
||||||
|
/// Reserves space for N elements
|
||||||
|
fn reserve(count: uint) {
|
||||||
|
vec::reserve(self.data, count)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swaps out the current vector and hands it off to a user-provided
|
* Swaps out the current vector and hands it off to a user-provided
|
||||||
* function `f`. The function should transform it however is desired
|
* function `f`. The function should transform it however is desired
|
||||||
|
|||||||
@@ -509,10 +509,7 @@ fn push<T>(&v: ~[const T], +initval: T) {
|
|||||||
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||||
let fill = (**repr).fill;
|
let fill = (**repr).fill;
|
||||||
if (**repr).alloc > fill {
|
if (**repr).alloc > fill {
|
||||||
(**repr).fill += sys::size_of::<T>();
|
push_fast(v, initval);
|
||||||
let p = ptr::addr_of((**repr).data);
|
|
||||||
let p = ptr::offset(p, fill) as *mut T;
|
|
||||||
rusti::move_val_init(*p, initval);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
push_slow(v, initval);
|
push_slow(v, initval);
|
||||||
@@ -520,9 +517,21 @@ fn push<T>(&v: ~[const T], +initval: T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This doesn't bother to make sure we have space.
|
||||||
|
#[inline(always)] // really pretty please
|
||||||
|
unsafe fn push_fast<T>(&v: ~[const T], +initval: T) {
|
||||||
|
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||||
|
let fill = (**repr).fill;
|
||||||
|
(**repr).fill += sys::size_of::<T>();
|
||||||
|
let p = ptr::addr_of((**repr).data);
|
||||||
|
let p = ptr::offset(p, fill) as *mut T;
|
||||||
|
rusti::move_val_init(*p, initval);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
fn push_slow<T>(&v: ~[const T], +initval: T) {
|
fn push_slow<T>(&v: ~[const T], +initval: T) {
|
||||||
reserve_at_least(v, v.len() + 1u);
|
reserve_at_least(v, v.len() + 1u);
|
||||||
push(v, initval);
|
unsafe { push_fast(v, initval) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unchecked vector indexing
|
// Unchecked vector indexing
|
||||||
@@ -644,7 +653,6 @@ fn grow_fn<T>(&v: ~[const T], n: uint, op: init_op<T>) {
|
|||||||
* of the vector, expands the vector by replicating `initval` to fill the
|
* of the vector, expands the vector by replicating `initval` to fill the
|
||||||
* intervening space.
|
* intervening space.
|
||||||
*/
|
*/
|
||||||
#[inline(always)]
|
|
||||||
fn grow_set<T: copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
|
fn grow_set<T: copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
|
||||||
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
|
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
|
||||||
v[index] = val;
|
v[index] = val;
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ enum smallintmap<T:copy> {
|
|||||||
|
|
||||||
/// Create a smallintmap
|
/// Create a smallintmap
|
||||||
fn mk<T: copy>() -> smallintmap<T> {
|
fn mk<T: copy>() -> smallintmap<T> {
|
||||||
ret smallintmap_(@{v: dvec()});
|
let v = dvec();
|
||||||
|
ret smallintmap_(@{v: v});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,6 +27,7 @@ fn mk<T: copy>() -> smallintmap<T> {
|
|||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
|
fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
|
||||||
|
//#error("inserting key %?", key);
|
||||||
self.v.grow_set_elt(key, none, some(val));
|
self.v.grow_set_elt(key, none, some(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -364,7 +364,8 @@ fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
|
|||||||
enum inline_attr {
|
enum inline_attr {
|
||||||
ia_none,
|
ia_none,
|
||||||
ia_hint,
|
ia_hint,
|
||||||
ia_always
|
ia_always,
|
||||||
|
ia_never,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if something like #[inline] is found in the list of attrs.
|
/// True if something like #[inline] is found in the list of attrs.
|
||||||
@@ -376,6 +377,9 @@ fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
|
|||||||
ast::meta_list(@~"inline", items) {
|
ast::meta_list(@~"inline", items) {
|
||||||
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
|
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
|
||||||
ia_always
|
ia_always
|
||||||
|
} else if !vec::is_empty(
|
||||||
|
find_meta_items_by_name(items, ~"never")) {
|
||||||
|
ia_never
|
||||||
} else {
|
} else {
|
||||||
ia_hint
|
ia_hint
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,8 +545,8 @@ fn purity_fn_family(p: purity) -> char {
|
|||||||
|
|
||||||
fn should_inline(attrs: ~[attribute]) -> bool {
|
fn should_inline(attrs: ~[attribute]) -> bool {
|
||||||
alt attr::find_inline_attr(attrs) {
|
alt attr::find_inline_attr(attrs) {
|
||||||
attr::ia_none { false }
|
attr::ia_none | attr::ia_never { false }
|
||||||
attr::ia_hint | attr::ia_always { true }
|
attr::ia_hint | attr::ia_always { true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -456,6 +456,7 @@ fn set_inline_hint_if_appr(attrs: ~[ast::attribute],
|
|||||||
alt attr::find_inline_attr(attrs) {
|
alt attr::find_inline_attr(attrs) {
|
||||||
attr::ia_hint { set_inline_hint(llfn); }
|
attr::ia_hint { set_inline_hint(llfn); }
|
||||||
attr::ia_always { set_always_inline(llfn); }
|
attr::ia_always { set_always_inline(llfn); }
|
||||||
|
attr::ia_never { set_no_inline(llfn); }
|
||||||
attr::ia_none { /* fallthrough */ }
|
attr::ia_none { /* fallthrough */ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user