Skip to content

Commit

Permalink
Changed Arena API to make it usable once more.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiez committed Jun 23, 2013
1 parent 6762754 commit 7ba1a23
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions 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.
//
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

5 comments on commit 7ba1a23

@bors
Copy link
Contributor

@bors bors commented on 7ba1a23 Jun 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at Thiez@7ba1a23

@bors
Copy link
Contributor

@bors bors commented on 7ba1a23 Jun 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Thiez/rust/fixbench = 7ba1a23 into auto

@bors
Copy link
Contributor

@bors bors commented on 7ba1a23 Jun 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thiez/rust/fixbench = 7ba1a23 merged ok, testing candidate = c6515ee

@bors
Copy link
Contributor

@bors bors commented on 7ba1a23 Jun 24, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c6515ee

Please sign in to comment.