Skip to content

Commit 3aee39a

Browse files
committed
Add #[inline(never)], and also fixed inlining on vec::push
1 parent 987814f commit 3aee39a

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

src/libcore/dvec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ impl private_methods<A> for dvec<A> {
108108
// almost nothing works without the copy bound due to limitations
109109
// around closures.
110110
impl extensions<A> for dvec<A> {
111+
/// Reserves space for N elements
112+
fn reserve(count: uint) {
113+
vec::reserve(self.data, count)
114+
}
115+
111116
/**
112117
* Swaps out the current vector and hands it off to a user-provided
113118
* function `f`. The function should transform it however is desired

src/libcore/vec.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,20 +509,29 @@ fn push<T>(&v: ~[const T], +initval: T) {
509509
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
510510
let fill = (**repr).fill;
511511
if (**repr).alloc > fill {
512-
(**repr).fill += sys::size_of::<T>();
513-
let p = ptr::addr_of((**repr).data);
514-
let p = ptr::offset(p, fill) as *mut T;
515-
rusti::move_val_init(*p, initval);
512+
push_fast(v, initval);
516513
}
517514
else {
518515
push_slow(v, initval);
519516
}
520517
}
521518
}
522519

520+
// This doesn't bother to make sure we have space.
521+
#[inline(always)] // really pretty please
522+
unsafe fn push_fast<T>(&v: ~[const T], +initval: T) {
523+
let repr: **unsafe::vec_repr = ::unsafe::reinterpret_cast(addr_of(v));
524+
let fill = (**repr).fill;
525+
(**repr).fill += sys::size_of::<T>();
526+
let p = ptr::addr_of((**repr).data);
527+
let p = ptr::offset(p, fill) as *mut T;
528+
rusti::move_val_init(*p, initval);
529+
}
530+
531+
#[inline(never)]
523532
fn push_slow<T>(&v: ~[const T], +initval: T) {
524533
reserve_at_least(v, v.len() + 1u);
525-
push(v, initval);
534+
unsafe { push_fast(v, initval) }
526535
}
527536

528537
// Unchecked vector indexing
@@ -644,7 +653,6 @@ fn grow_fn<T>(&v: ~[const T], n: uint, op: init_op<T>) {
644653
* of the vector, expands the vector by replicating `initval` to fill the
645654
* intervening space.
646655
*/
647-
#[inline(always)]
648656
fn grow_set<T: copy>(&v: ~[mut T], index: uint, initval: T, val: T) {
649657
if index >= len(v) { grow(v, index - len(v) + 1u, initval); }
650658
v[index] = val;

src/libstd/smallintmap.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ enum smallintmap<T:copy> {
1717

1818
/// Create a smallintmap
1919
fn mk<T: copy>() -> smallintmap<T> {
20-
ret smallintmap_(@{v: dvec()});
20+
let v = dvec();
21+
ret smallintmap_(@{v: v});
2122
}
2223

2324
/**
@@ -26,6 +27,7 @@ fn mk<T: copy>() -> smallintmap<T> {
2627
*/
2728
#[inline(always)]
2829
fn insert<T: copy>(self: smallintmap<T>, key: uint, val: T) {
30+
//#error("inserting key %?", key);
2931
self.v.grow_set_elt(key, none, some(val));
3032
}
3133

src/libsyntax/attr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
364364
enum inline_attr {
365365
ia_none,
366366
ia_hint,
367-
ia_always
367+
ia_always,
368+
ia_never,
368369
}
369370
370371
/// 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 {
376377
ast::meta_list(@~"inline", items) {
377378
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
378379
ia_always
380+
} else if !vec::is_empty(
381+
find_meta_items_by_name(items, ~"never")) {
382+
ia_never
379383
} else {
380384
ia_hint
381385
}

src/rustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ fn purity_fn_family(p: purity) -> char {
545545

546546
fn should_inline(attrs: ~[attribute]) -> bool {
547547
alt attr::find_inline_attr(attrs) {
548-
attr::ia_none { false }
549-
attr::ia_hint | attr::ia_always { true }
548+
attr::ia_none | attr::ia_never { false }
549+
attr::ia_hint | attr::ia_always { true }
550550
}
551551
}
552552

src/rustc/middle/trans/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ fn set_inline_hint_if_appr(attrs: ~[ast::attribute],
456456
alt attr::find_inline_attr(attrs) {
457457
attr::ia_hint { set_inline_hint(llfn); }
458458
attr::ia_always { set_always_inline(llfn); }
459+
attr::ia_never { set_no_inline(llfn); }
459460
attr::ia_none { /* fallthrough */ }
460461
}
461462
}

0 commit comments

Comments
 (0)