diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-03-28 22:09:54 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-03-29 08:41:26 -0700 |
| commit | b210c7ad9741fa8d560494a5686d4ac62519899f (patch) | |
| tree | 4a6b5a64897d544a5c07eac45ea6910035ac21b2 /src/libstd | |
| parent | 1d25594657826bf9be14dee014913447851e76b4 (diff) | |
| download | rust-b210c7ad9741fa8d560494a5686d4ac62519899f.tar.gz rust-b210c7ad9741fa8d560494a5686d4ac62519899f.zip | |
stdlib: Allow the fast path of arena allocation to be CCI'd. 15% improvement on binary-trees.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/arena.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 1414f27285d..d61131c9d47 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -22,22 +22,27 @@ fn arena() -> 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) -> *() { let alignm1 = align - 1u; let mut head = list::head(self.chunks); let mut start = head.fill; start = (start + alignm1) & !alignm1; - let mut end = start + n_bytes; - + let end = start + n_bytes; if end > vec::alloc_len(head.data) { - // Allocate a new chunk. - 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; + ret self.alloc_grow(n_bytes, align); } unsafe { |
