Skip to content

Commit 7ba1a23

Browse files
committed
Changed Arena API to make it usable once more.
1 parent 6762754 commit 7ba1a23

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/libextra/arena.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -39,7 +39,7 @@ use core::prelude::*;
3939
use list::{MutList, MutCons, MutNil};
4040

4141
use core::at_vec;
42-
use core::cast::{transmute, transmute_mut_region};
42+
use core::cast::{transmute, transmute_mut, transmute_mut_region};
4343
use core::cast;
4444
use core::libc::size_t;
4545
use core::ptr;
@@ -74,6 +74,7 @@ struct Chunk {
7474
is_pod: bool,
7575
}
7676

77+
#[mutable]
7778
pub struct Arena {
7879
// The head is separated out from the list as a unbenchmarked
7980
// microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
269270

270271
// The external interface
271272
#[inline]
272-
pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T {
273+
pub fn alloc<'a, T>(&'a self, op: &fn() -> T) -> &'a T {
273274
unsafe {
274275
// XXX: Borrow check
275-
let this = transmute_mut_region(self);
276-
if !intrinsics::needs_drop::<T>() {
277-
return this.alloc_pod(op);
276+
let this = transmute_mut(self);
277+
if intrinsics::needs_drop::<T>() {
278+
this.alloc_nonpod(op)
279+
} else {
280+
this.alloc_pod(op)
278281
}
279-
// XXX: Borrow check
280-
let this = transmute_mut_region(self);
281-
this.alloc_nonpod(op)
282282
}
283283
}
284284
}
285285

286286
#[test]
287287
fn test_arena_destructors() {
288-
let mut arena = Arena();
288+
let arena = Arena();
289289
for uint::range(0, 10) |i| {
290290
// Arena allocate something with drop glue to make sure it
291291
// doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
300300
#[should_fail]
301301
#[ignore(cfg(windows))]
302302
fn test_arena_destructors_fail() {
303-
let mut arena = Arena();
303+
let arena = Arena();
304304
// Put some stuff in the arena.
305305
for uint::range(0, 10) |i| {
306306
// Arena allocate something with drop glue to make sure it

0 commit comments

Comments
 (0)