mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
stdlib: Allow the fast path of arena allocation to be CCI'd. 15% improvement on binary-trees.
This commit is contained in:
parent
1d25594657
commit
b210c7ad97
@ -22,22 +22,27 @@ fn arena() -> arena {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl arena for arena {
|
impl arena for arena {
|
||||||
|
fn alloc_grow(n_bytes: uint, align: uint) -> *() {
|
||||||
|
// Allocate a new chunk.
|
||||||
|
let mut head = list::head(self.chunks);
|
||||||
|
let chunk_size = vec::alloc_len(head.data);
|
||||||
|
let new_min_chunk_size = uint::max(n_bytes, chunk_size);
|
||||||
|
head = chunk(uint::next_power_of_two(new_min_chunk_size));
|
||||||
|
self.chunks = list::cons(head, @self.chunks);
|
||||||
|
|
||||||
|
ret self.alloc(n_bytes, align);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
fn alloc(n_bytes: uint, align: uint) -> *() {
|
fn alloc(n_bytes: uint, align: uint) -> *() {
|
||||||
let alignm1 = align - 1u;
|
let alignm1 = align - 1u;
|
||||||
let mut head = list::head(self.chunks);
|
let mut head = list::head(self.chunks);
|
||||||
|
|
||||||
let mut start = head.fill;
|
let mut start = head.fill;
|
||||||
start = (start + alignm1) & !alignm1;
|
start = (start + alignm1) & !alignm1;
|
||||||
let mut end = start + n_bytes;
|
let end = start + n_bytes;
|
||||||
|
|
||||||
if end > vec::alloc_len(head.data) {
|
if end > vec::alloc_len(head.data) {
|
||||||
// Allocate a new chunk.
|
ret self.alloc_grow(n_bytes, align);
|
||||||
let new_min_chunk_size = uint::max(n_bytes,
|
|
||||||
vec::alloc_len(head.data));
|
|
||||||
head = chunk(uint::next_power_of_two(new_min_chunk_size));
|
|
||||||
self.chunks = list::cons(head, @self.chunks);
|
|
||||||
start = 0u;
|
|
||||||
end = n_bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
Loading…
Reference in New Issue
Block a user