Changed Arena API to make it usable once more.
This commit is contained in:
parent
6762754d5b
commit
7ba1a239a4
1 changed files with 11 additions and 11 deletions
|
@ -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
|
// file at the top-level directory of this distribution and at
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
//
|
//
|
||||||
|
@ -39,7 +39,7 @@ use core::prelude::*;
|
||||||
use list::{MutList, MutCons, MutNil};
|
use list::{MutList, MutCons, MutNil};
|
||||||
|
|
||||||
use core::at_vec;
|
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::cast;
|
||||||
use core::libc::size_t;
|
use core::libc::size_t;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
|
@ -74,6 +74,7 @@ struct Chunk {
|
||||||
is_pod: bool,
|
is_pod: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[mutable]
|
||||||
pub struct Arena {
|
pub struct Arena {
|
||||||
// The head is separated out from the list as a unbenchmarked
|
// The head is separated out from the list as a unbenchmarked
|
||||||
// microoptimization, to avoid needing to case on the list to
|
// microoptimization, to avoid needing to case on the list to
|
||||||
|
@ -269,23 +270,22 @@ impl Arena {
|
||||||
|
|
||||||
// The external interface
|
// The external interface
|
||||||
#[inline]
|
#[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 {
|
unsafe {
|
||||||
// XXX: Borrow check
|
// XXX: Borrow check
|
||||||
let this = transmute_mut_region(self);
|
let this = transmute_mut(self);
|
||||||
if !intrinsics::needs_drop::<T>() {
|
if intrinsics::needs_drop::<T>() {
|
||||||
return this.alloc_pod(op);
|
this.alloc_nonpod(op)
|
||||||
|
} else {
|
||||||
|
this.alloc_pod(op)
|
||||||
}
|
}
|
||||||
// XXX: Borrow check
|
|
||||||
let this = transmute_mut_region(self);
|
|
||||||
this.alloc_nonpod(op)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_arena_destructors() {
|
fn test_arena_destructors() {
|
||||||
let mut arena = Arena();
|
let arena = Arena();
|
||||||
for uint::range(0, 10) |i| {
|
for uint::range(0, 10) |i| {
|
||||||
// Arena allocate something with drop glue to make sure it
|
// Arena allocate something with drop glue to make sure it
|
||||||
// doesn't leak.
|
// doesn't leak.
|
||||||
|
@ -300,7 +300,7 @@ fn test_arena_destructors() {
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
#[ignore(cfg(windows))]
|
#[ignore(cfg(windows))]
|
||||||
fn test_arena_destructors_fail() {
|
fn test_arena_destructors_fail() {
|
||||||
let mut arena = Arena();
|
let arena = Arena();
|
||||||
// Put some stuff in the arena.
|
// Put some stuff in the arena.
|
||||||
for uint::range(0, 10) |i| {
|
for uint::range(0, 10) |i| {
|
||||||
// Arena allocate something with drop glue to make sure it
|
// Arena allocate something with drop glue to make sure it
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue