about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthijs Hofstra <thiezz@gmail.com>2013-06-16 17:50:16 +0200
committerMatthijs Hofstra <thiezz@gmail.com>2013-06-24 00:09:04 +0200
commit7ba1a239a4fc54f101434128e76b370b926cb8ef (patch)
treee103836108964824b6286b0049d3419f52e820de
parent6762754d5b718d2d3f938963d2a4d82eb20eb9fd (diff)
Changed Arena API to make it usable once more.
-rw-r--r--src/libextra/arena.rs22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs
index db4cf564bab..302f1fbeb04 100644
--- a/src/libextra/arena.rs
+++ b/src/libextra/arena.rs
@@ -1,4 +1,4 @@
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -39,7 +39,7 @@ use core::prelude::*;
 use list::{MutList, MutCons, MutNil};
 
 use core::at_vec;
-use core::cast::{transmute, transmute_mut_region};
+use core::cast::{transmute, transmute_mut, transmute_mut_region};
 use core::cast;
 use core::libc::size_t;
 use core::ptr;
@@ -74,6 +74,7 @@ struct Chunk {
     is_pod: bool,
 }
 
+#[mutable]
 pub struct Arena {
     // The head is separated out from the list as a unbenchmarked
     // microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
 
     // The external interface
     #[inline]
-    pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
+    pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
         unsafe {
             // XXX: Borrow check
-            let this = transmute_mut_region(self);
-            if !intrinsics::needs_drop::<T>() {
-                return this.alloc_pod(op);
+            let this = transmute_mut(self);
+            if intrinsics::needs_drop::<T>() {
+                this.alloc_nonpod(op)
+            } else {
+                this.alloc_pod(op)
             }
-            // XXX: Borrow check
-            let this = transmute_mut_region(self);
-            this.alloc_nonpod(op)
         }
     }
 }
 
 #[test]
 fn test_arena_destructors() {
-    let mut arena = Arena();
+    let arena = Arena();
     for uint::range(0, 10) |i| {
         // Arena allocate something with drop glue to make sure it
         // doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
 #[should_fail]
 #[ignore(cfg(windows))]
 fn test_arena_destructors_fail() {
-    let mut arena = Arena();
+    let arena = Arena();
     // Put some stuff in the arena.
     for uint::range(0, 10) |i| {
         // Arena allocate something with drop glue to make sure it