diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 47b64d7695168..ae4356eb4bacc 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -67,17 +67,16 @@ pub struct Arena { priv chunks: @mut MutList, } -#[unsafe_destructor] -impl Drop for Arena { - fn drop(&self) { - unsafe { - destroy_chunk(&self.head); - do self.chunks.each |chunk| { - if !chunk.is_pod { - destroy_chunk(chunk); - } - true - }; +impl Arena { + pub fn new() -> Arena { + Arena::new_with_size(32u) + } + + pub fn new_with_size(initial_size: uint) -> Arena { + Arena { + head: chunk(initial_size, false), + pod_head: chunk(initial_size, true), + chunks: @mut MutNil, } } } @@ -92,18 +91,21 @@ fn chunk(size: uint, is_pod: bool) -> Chunk { } } -pub fn arena_with_size(initial_size: uint) -> Arena { - Arena { - head: chunk(initial_size, false), - pod_head: chunk(initial_size, true), - chunks: @mut MutNil, +#[unsafe_destructor] +impl Drop for Arena { + fn drop(&self) { + unsafe { + destroy_chunk(&self.head); + do self.chunks.each |chunk| { + if !chunk.is_pod { + destroy_chunk(chunk); + } + true + }; + } } } -pub fn Arena() -> Arena { - arena_with_size(32u) -} - #[inline] fn round_up_to(base: uint, align: uint) -> uint { (base + (align - 1)) & !(align - 1) @@ -276,7 +278,7 @@ impl Arena { #[test] fn test_arena_destructors() { - let arena = Arena(); + let arena = Arena::new(); for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it // doesn't leak. @@ -291,7 +293,7 @@ fn test_arena_destructors() { #[should_fail] #[ignore(cfg(windows))] fn test_arena_destructors_fail() { - let arena = Arena(); + let arena = Arena::new(); // Put some stuff in the arena. for i in range(0u, 10) { // Arena allocate something with drop glue to make sure it diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 596a5b5422a5d..57bf33fb2fdac 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -9,7 +9,7 @@ // except according to those terms. extern mod extra; -use extra::arena; +use extra::arena::Arena; enum Tree<'self> { Nil, @@ -25,7 +25,7 @@ fn item_check(t: &Tree) -> int { } } -fn bottom_up_tree<'r>(arena: &'r arena::Arena, item: int, depth: int) +fn bottom_up_tree<'r>(arena: &'r Arena, item: int, depth: int) -> &'r Tree<'r> { if depth > 0 { return arena.alloc( @@ -57,7 +57,7 @@ fn main() { max_depth = n; } - let stretch_arena = arena::Arena(); + let stretch_arena = Arena::new(); let stretch_depth = max_depth + 1; let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth); @@ -65,7 +65,7 @@ fn main() { stretch_depth, item_check(stretch_tree)); - let long_lived_arena = arena::Arena(); + let long_lived_arena = Arena::new(); let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth); let mut depth = min_depth; while depth <= max_depth { diff --git a/src/test/run-pass/placement-new-arena.rs b/src/test/run-pass/placement-new-arena.rs index 9500f83b76b09..f2063b583e4f9 100644 --- a/src/test/run-pass/placement-new-arena.rs +++ b/src/test/run-pass/placement-new-arena.rs @@ -11,10 +11,10 @@ // except according to those terms. extern mod extra; -use extra::arena; +use extra::arena::Arena; pub fn main() { - let mut arena = arena::Arena(); + let mut arena = Arena::new(); let p = &mut arena; let x = p.alloc(|| 4u); printf!("%u", *x);