@@ -362,38 +362,6 @@ impl<'longer_than_self> Arena<'longer_than_self> {
362
362
}
363
363
}
364
364
365
- #[ test]
366
- fn test_arena_destructors ( ) {
367
- let arena = Arena :: new ( ) ;
368
- for i in 0 ..10 {
369
- // Arena allocate something with drop glue to make sure it
370
- // doesn't leak.
371
- arena. alloc ( || Rc :: new ( i) ) ;
372
- // Allocate something with funny size and alignment, to keep
373
- // things interesting.
374
- arena. alloc ( || [ 0u8 , 1u8 , 2u8 ] ) ;
375
- }
376
- }
377
-
378
- #[ test]
379
- #[ should_panic]
380
- fn test_arena_destructors_fail ( ) {
381
- let arena = Arena :: new ( ) ;
382
- // Put some stuff in the arena.
383
- for i in 0 ..10 {
384
- // Arena allocate something with drop glue to make sure it
385
- // doesn't leak.
386
- arena. alloc ( || Rc :: new ( i) ) ;
387
- // Allocate something with funny size and alignment, to keep
388
- // things interesting.
389
- arena. alloc ( || [ 0u8 , 1 , 2 ] ) ;
390
- }
391
- // Now, panic while allocating
392
- arena. alloc :: < Rc < i32 > , _ > ( || {
393
- panic ! ( ) ;
394
- } ) ;
395
- }
396
-
397
365
/// A faster arena that can hold objects of only one type.
398
366
pub struct TypedArena < T > {
399
367
/// A pointer to the next object to be allocated.
@@ -693,40 +661,6 @@ mod tests {
693
661
}
694
662
}
695
663
696
- #[ bench]
697
- pub fn bench_noncopy ( b : & mut Bencher ) {
698
- let arena = TypedArena :: new ( ) ;
699
- b. iter ( || {
700
- arena. alloc ( Noncopy {
701
- string : "hello world" . to_string ( ) ,
702
- array : vec ! [ 1 , 2 , 3 , 4 , 5 ] ,
703
- } )
704
- } )
705
- }
706
-
707
- #[ bench]
708
- pub fn bench_noncopy_nonarena ( b : & mut Bencher ) {
709
- b. iter ( || {
710
- let _: Box < _ > = Box :: new ( Noncopy {
711
- string : "hello world" . to_string ( ) ,
712
- array : vec ! [ 1 , 2 , 3 , 4 , 5 ] ,
713
- } ) ;
714
- } )
715
- }
716
-
717
- #[ bench]
718
- pub fn bench_noncopy_old_arena ( b : & mut Bencher ) {
719
- let arena = Arena :: new ( ) ;
720
- b. iter ( || {
721
- arena. alloc ( || {
722
- Noncopy {
723
- string : "hello world" . to_string ( ) ,
724
- array : vec ! [ 1 , 2 , 3 , 4 , 5 ] ,
725
- }
726
- } )
727
- } )
728
- }
729
-
730
664
#[ test]
731
665
pub fn test_typed_arena_zero_sized ( ) {
732
666
let arena = TypedArena :: new ( ) ;
@@ -798,4 +732,68 @@ mod tests {
798
732
}
799
733
}
800
734
}
735
+
736
+ #[ test]
737
+ fn test_arena_destructors ( ) {
738
+ let arena = Arena :: new ( ) ;
739
+ for i in 0 ..10 {
740
+ // Arena allocate something with drop glue to make sure it
741
+ // doesn't leak.
742
+ arena. alloc ( || Rc :: new ( i) ) ;
743
+ // Allocate something with funny size and alignment, to keep
744
+ // things interesting.
745
+ arena. alloc ( || [ 0u8 , 1u8 , 2u8 ] ) ;
746
+ }
747
+ }
748
+
749
+ #[ test]
750
+ #[ should_panic]
751
+ fn test_arena_destructors_fail ( ) {
752
+ let arena = Arena :: new ( ) ;
753
+ // Put some stuff in the arena.
754
+ for i in 0 ..10 {
755
+ // Arena allocate something with drop glue to make sure it
756
+ // doesn't leak.
757
+ arena. alloc ( || { Rc :: new ( i) } ) ;
758
+ // Allocate something with funny size and alignment, to keep
759
+ // things interesting.
760
+ arena. alloc ( || { [ 0u8 , 1 , 2 ] } ) ;
761
+ }
762
+ // Now, panic while allocating
763
+ arena. alloc :: < Rc < i32 > , _ > ( || {
764
+ panic ! ( ) ;
765
+ } ) ;
766
+ }
767
+
768
+ #[ bench]
769
+ pub fn bench_noncopy ( b : & mut Bencher ) {
770
+ let arena = TypedArena :: new ( ) ;
771
+ b. iter ( || {
772
+ arena. alloc ( Noncopy {
773
+ string : "hello world" . to_string ( ) ,
774
+ array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
775
+ } )
776
+ } )
777
+ }
778
+
779
+ #[ bench]
780
+ pub fn bench_noncopy_nonarena ( b : & mut Bencher ) {
781
+ b. iter ( || {
782
+ let _: Box < _ > = Box :: new ( Noncopy {
783
+ string : "hello world" . to_string ( ) ,
784
+ array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
785
+ } ) ;
786
+ } )
787
+ }
788
+
789
+ #[ bench]
790
+ pub fn bench_noncopy_old_arena ( b : & mut Bencher ) {
791
+ let arena = Arena :: new ( ) ;
792
+ b. iter ( || {
793
+ arena. alloc ( || Noncopy {
794
+ string : "hello world" . to_string ( ) ,
795
+ array : vec ! ( 1 , 2 , 3 , 4 , 5 ) ,
796
+ } )
797
+ } )
798
+ }
801
799
}
0 commit comments