Skip to content

Commit b210c7a

Browse files
committed
stdlib: Allow the fast path of arena allocation to be CCI'd. 15% improvement on binary-trees.
1 parent 1d25594 commit b210c7a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/libstd/arena.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@ fn arena() -> arena {
2222
}
2323

2424
impl arena for arena {
25+
fn alloc_grow(n_bytes: uint, align: uint) -> *() {
26+
// Allocate a new chunk.
27+
let mut head = list::head(self.chunks);
28+
let chunk_size = vec::alloc_len(head.data);
29+
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
30+
head = chunk(uint::next_power_of_two(new_min_chunk_size));
31+
self.chunks = list::cons(head, @self.chunks);
32+
33+
ret self.alloc(n_bytes, align);
34+
}
35+
36+
#[inline(always)]
2537
fn alloc(n_bytes: uint, align: uint) -> *() {
2638
let alignm1 = align - 1u;
2739
let mut head = list::head(self.chunks);
2840

2941
let mut start = head.fill;
3042
start = (start + alignm1) & !alignm1;
31-
let mut end = start + n_bytes;
32-
43+
let end = start + n_bytes;
3344
if end > vec::alloc_len(head.data) {
34-
// Allocate a new chunk.
35-
let new_min_chunk_size = uint::max(n_bytes,
36-
vec::alloc_len(head.data));
37-
head = chunk(uint::next_power_of_two(new_min_chunk_size));
38-
self.chunks = list::cons(head, @self.chunks);
39-
start = 0u;
40-
end = n_bytes;
45+
ret self.alloc_grow(n_bytes, align);
4146
}
4247

4348
unsafe {

0 commit comments

Comments
 (0)