@@ -114,10 +114,9 @@ impl<T> TypedArenaChunk<T> {
114
114
115
115
const PAGE : usize = 4096 ;
116
116
117
- impl < T > TypedArena < T > {
117
+ impl < T > Default for TypedArena < T > {
118
118
/// Creates a new `TypedArena`.
119
- #[ inline]
120
- pub fn new ( ) -> TypedArena < T > {
119
+ fn default ( ) -> TypedArena < T > {
121
120
TypedArena {
122
121
// We set both `ptr` and `end` to 0 so that the first call to
123
122
// alloc() will trigger a grow().
@@ -127,7 +126,9 @@ impl<T> TypedArena<T> {
127
126
_own : PhantomData ,
128
127
}
129
128
}
129
+ }
130
130
131
+ impl < T > TypedArena < T > {
131
132
/// Allocates an object in the `TypedArena`, returning a reference to it.
132
133
#[ inline]
133
134
pub fn alloc ( & self , object : T ) -> & mut T {
@@ -296,15 +297,17 @@ pub struct DroplessArena {
296
297
297
298
unsafe impl Send for DroplessArena { }
298
299
299
- impl DroplessArena {
300
- pub fn new ( ) -> DroplessArena {
300
+ impl Default for DroplessArena {
301
+ fn default ( ) -> DroplessArena {
301
302
DroplessArena {
302
303
ptr : Cell :: new ( 0 as * mut u8 ) ,
303
304
end : Cell :: new ( 0 as * mut u8 ) ,
304
- chunks : RefCell :: new ( vec ! [ ] ) ,
305
+ chunks : Default :: default ( ) ,
305
306
}
306
307
}
308
+ }
307
309
310
+ impl DroplessArena {
308
311
pub fn in_arena < T : ?Sized > ( & self , ptr : * const T ) -> bool {
309
312
let ptr = ptr as * const u8 as * mut u8 ;
310
313
for chunk in & * self . chunks . borrow ( ) {
@@ -419,18 +422,13 @@ impl DroplessArena {
419
422
}
420
423
}
421
424
425
+ #[ derive( Default ) ]
426
+ // FIXME(@Zoxc): this type is entirely unused in rustc
422
427
pub struct SyncTypedArena < T > {
423
428
lock : MTLock < TypedArena < T > > ,
424
429
}
425
430
426
431
impl < T > SyncTypedArena < T > {
427
- #[ inline( always) ]
428
- pub fn new ( ) -> SyncTypedArena < T > {
429
- SyncTypedArena {
430
- lock : MTLock :: new ( TypedArena :: new ( ) )
431
- }
432
- }
433
-
434
432
#[ inline( always) ]
435
433
pub fn alloc ( & self , object : T ) -> & mut T {
436
434
// Extend the lifetime of the result since it's limited to the lock guard
@@ -452,18 +450,12 @@ impl<T> SyncTypedArena<T> {
452
450
}
453
451
}
454
452
453
+ #[ derive( Default ) ]
455
454
pub struct SyncDroplessArena {
456
455
lock : MTLock < DroplessArena > ,
457
456
}
458
457
459
458
impl SyncDroplessArena {
460
- #[ inline( always) ]
461
- pub fn new ( ) -> SyncDroplessArena {
462
- SyncDroplessArena {
463
- lock : MTLock :: new ( DroplessArena :: new ( ) )
464
- }
465
- }
466
-
467
459
#[ inline( always) ]
468
460
pub fn in_arena < T : ?Sized > ( & self , ptr : * const T ) -> bool {
469
461
self . lock . lock ( ) . in_arena ( ptr)
@@ -508,7 +500,7 @@ mod tests {
508
500
509
501
#[ test]
510
502
pub fn test_unused ( ) {
511
- let arena: TypedArena < Point > = TypedArena :: new ( ) ;
503
+ let arena: TypedArena < Point > = TypedArena :: default ( ) ;
512
504
assert ! ( arena. chunks. borrow( ) . is_empty( ) ) ;
513
505
}
514
506
@@ -546,7 +538,7 @@ mod tests {
546
538
}
547
539
}
548
540
549
- let arena = Wrap ( TypedArena :: new ( ) ) ;
541
+ let arena = Wrap ( TypedArena :: default ( ) ) ;
550
542
551
543
let result = arena. alloc_outer ( || Outer {
552
544
inner : arena. alloc_inner ( || Inner { value : 10 } ) ,
@@ -557,15 +549,15 @@ mod tests {
557
549
558
550
#[ test]
559
551
pub fn test_copy ( ) {
560
- let arena = TypedArena :: new ( ) ;
552
+ let arena = TypedArena :: default ( ) ;
561
553
for _ in 0 ..100000 {
562
554
arena. alloc ( Point { x : 1 , y : 2 , z : 3 } ) ;
563
555
}
564
556
}
565
557
566
558
#[ bench]
567
559
pub fn bench_copy ( b : & mut Bencher ) {
568
- let arena = TypedArena :: new ( ) ;
560
+ let arena = TypedArena :: default ( ) ;
569
561
b. iter ( || arena. alloc ( Point { x : 1 , y : 2 , z : 3 } ) )
570
562
}
571
563
@@ -584,7 +576,7 @@ mod tests {
584
576
585
577
#[ test]
586
578
pub fn test_noncopy ( ) {
587
- let arena = TypedArena :: new ( ) ;
579
+ let arena = TypedArena :: default ( ) ;
588
580
for _ in 0 ..100000 {
589
581
arena. alloc ( Noncopy {
590
582
string : "hello world" . to_string ( ) ,
@@ -595,15 +587,15 @@ mod tests {
595
587
596
588
#[ test]
597
589
pub fn test_typed_arena_zero_sized ( ) {
598
- let arena = TypedArena :: new ( ) ;
590
+ let arena = TypedArena :: default ( ) ;
599
591
for _ in 0 ..100000 {
600
592
arena. alloc ( ( ) ) ;
601
593
}
602
594
}
603
595
604
596
#[ test]
605
597
pub fn test_typed_arena_clear ( ) {
606
- let mut arena = TypedArena :: new ( ) ;
598
+ let mut arena = TypedArena :: default ( ) ;
607
599
for _ in 0 ..10 {
608
600
arena. clear ( ) ;
609
601
for _ in 0 ..10000 {
@@ -628,7 +620,7 @@ mod tests {
628
620
fn test_typed_arena_drop_count ( ) {
629
621
let counter = Cell :: new ( 0 ) ;
630
622
{
631
- let arena: TypedArena < DropCounter > = TypedArena :: new ( ) ;
623
+ let arena: TypedArena < DropCounter > = TypedArena :: default ( ) ;
632
624
for _ in 0 ..100 {
633
625
// Allocate something with drop glue to make sure it doesn't leak.
634
626
arena. alloc ( DropCounter { count : & counter } ) ;
@@ -640,7 +632,7 @@ mod tests {
640
632
#[ test]
641
633
fn test_typed_arena_drop_on_clear ( ) {
642
634
let counter = Cell :: new ( 0 ) ;
643
- let mut arena: TypedArena < DropCounter > = TypedArena :: new ( ) ;
635
+ let mut arena: TypedArena < DropCounter > = TypedArena :: default ( ) ;
644
636
for i in 0 ..10 {
645
637
for _ in 0 ..100 {
646
638
// Allocate something with drop glue to make sure it doesn't leak.
@@ -667,7 +659,7 @@ mod tests {
667
659
fn test_typed_arena_drop_small_count ( ) {
668
660
DROP_COUNTER . with ( |c| c. set ( 0 ) ) ;
669
661
{
670
- let arena: TypedArena < SmallDroppable > = TypedArena :: new ( ) ;
662
+ let arena: TypedArena < SmallDroppable > = TypedArena :: default ( ) ;
671
663
for _ in 0 ..100 {
672
664
// Allocate something with drop glue to make sure it doesn't leak.
673
665
arena. alloc ( SmallDroppable ) ;
@@ -679,7 +671,7 @@ mod tests {
679
671
680
672
#[ bench]
681
673
pub fn bench_noncopy ( b : & mut Bencher ) {
682
- let arena = TypedArena :: new ( ) ;
674
+ let arena = TypedArena :: default ( ) ;
683
675
b. iter ( || {
684
676
arena. alloc ( Noncopy {
685
677
string : "hello world" . to_string ( ) ,
0 commit comments