1
- // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
@@ -39,7 +39,7 @@ use core::prelude::*;
39
39
use list:: { MutList , MutCons , MutNil } ;
40
40
41
41
use core:: at_vec;
42
- use core:: cast:: { transmute, transmute_mut_region} ;
42
+ use core:: cast:: { transmute, transmute_mut , transmute_mut_region} ;
43
43
use core:: cast;
44
44
use core:: libc:: size_t;
45
45
use core:: ptr;
@@ -74,6 +74,7 @@ struct Chunk {
74
74
is_pod : bool ,
75
75
}
76
76
77
+ #[ mutable]
77
78
pub struct Arena {
78
79
// The head is separated out from the list as a unbenchmarked
79
80
// microoptimization, to avoid needing to case on the list to
@@ -269,23 +270,22 @@ impl Arena {
269
270
270
271
// The external interface
271
272
#[ 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 {
273
274
unsafe {
274
275
// 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)
278
281
}
279
- // XXX: Borrow check
280
- let this = transmute_mut_region ( self ) ;
281
- this. alloc_nonpod ( op)
282
282
}
283
283
}
284
284
}
285
285
286
286
#[ test]
287
287
fn test_arena_destructors ( ) {
288
- let mut arena = Arena ( ) ;
288
+ let arena = Arena ( ) ;
289
289
for uint:: range( 0 , 10 ) |i| {
290
290
// Arena allocate something with drop glue to make sure it
291
291
// doesn't leak.
@@ -300,7 +300,7 @@ fn test_arena_destructors() {
300
300
#[ should_fail]
301
301
#[ ignore( cfg( windows) ) ]
302
302
fn test_arena_destructors_fail( ) {
303
- let mut arena = Arena ( ) ;
303
+ let arena = Arena ( ) ;
304
304
// Put some stuff in the arena.
305
305
for uint:: range( 0 , 10 ) |i| {
306
306
// Arena allocate something with drop glue to make sure it
0 commit comments