@@ -114,10 +114,9 @@ impl<T> TypedArenaChunk<T> {
114114
115115const PAGE : usize = 4096 ;
116116
117- impl < T > TypedArena < T > {
117+ impl < T > Default for TypedArena < T > {
118118 /// Creates a new `TypedArena`.
119- #[ inline]
120- pub fn new ( ) -> TypedArena < T > {
119+ fn default ( ) -> TypedArena < T > {
121120 TypedArena {
122121 // We set both `ptr` and `end` to 0 so that the first call to
123122 // alloc() will trigger a grow().
@@ -127,7 +126,9 @@ impl<T> TypedArena<T> {
127126 _own : PhantomData ,
128127 }
129128 }
129+ }
130130
131+ impl < T > TypedArena < T > {
131132 /// Allocates an object in the `TypedArena`, returning a reference to it.
132133 #[ inline]
133134 pub fn alloc ( & self , object : T ) -> & mut T {
@@ -296,15 +297,17 @@ pub struct DroplessArena {
296297
297298unsafe impl Send for DroplessArena { }
298299
299- impl DroplessArena {
300- pub fn new ( ) -> DroplessArena {
300+ impl Default for DroplessArena {
301+ fn default ( ) -> DroplessArena {
301302 DroplessArena {
302303 ptr : Cell :: new ( 0 as * mut u8 ) ,
303304 end : Cell :: new ( 0 as * mut u8 ) ,
304- chunks : RefCell :: new ( vec ! [ ] ) ,
305+ chunks : Default :: default ( ) ,
305306 }
306307 }
308+ }
307309
310+ impl DroplessArena {
308311 pub fn in_arena < T : ?Sized > ( & self , ptr : * const T ) -> bool {
309312 let ptr = ptr as * const u8 as * mut u8 ;
310313 for chunk in & * self . chunks . borrow ( ) {
@@ -419,18 +422,13 @@ impl DroplessArena {
419422 }
420423}
421424
425+ #[ derive( Default ) ]
426+ // FIXME(@Zoxc): this type is entirely unused in rustc
422427pub struct SyncTypedArena < T > {
423428 lock : MTLock < TypedArena < T > > ,
424429}
425430
426431impl < T > SyncTypedArena < T > {
427- #[ inline( always) ]
428- pub fn new ( ) -> SyncTypedArena < T > {
429- SyncTypedArena {
430- lock : MTLock :: new ( TypedArena :: new ( ) )
431- }
432- }
433-
434432 #[ inline( always) ]
435433 pub fn alloc ( & self , object : T ) -> & mut T {
436434 // Extend the lifetime of the result since it's limited to the lock guard
@@ -452,18 +450,12 @@ impl<T> SyncTypedArena<T> {
452450 }
453451}
454452
453+ #[ derive( Default ) ]
455454pub struct SyncDroplessArena {
456455 lock : MTLock < DroplessArena > ,
457456}
458457
459458impl SyncDroplessArena {
460- #[ inline( always) ]
461- pub fn new ( ) -> SyncDroplessArena {
462- SyncDroplessArena {
463- lock : MTLock :: new ( DroplessArena :: new ( ) )
464- }
465- }
466-
467459 #[ inline( always) ]
468460 pub fn in_arena < T : ?Sized > ( & self , ptr : * const T ) -> bool {
469461 self . lock . lock ( ) . in_arena ( ptr)
@@ -508,7 +500,7 @@ mod tests {
508500
509501 #[ test]
510502 pub fn test_unused ( ) {
511- let arena: TypedArena < Point > = TypedArena :: new ( ) ;
503+ let arena: TypedArena < Point > = TypedArena :: default ( ) ;
512504 assert ! ( arena. chunks. borrow( ) . is_empty( ) ) ;
513505 }
514506
@@ -546,7 +538,7 @@ mod tests {
546538 }
547539 }
548540
549- let arena = Wrap ( TypedArena :: new ( ) ) ;
541+ let arena = Wrap ( TypedArena :: default ( ) ) ;
550542
551543 let result = arena. alloc_outer ( || Outer {
552544 inner : arena. alloc_inner ( || Inner { value : 10 } ) ,
@@ -557,15 +549,15 @@ mod tests {
557549
558550 #[ test]
559551 pub fn test_copy ( ) {
560- let arena = TypedArena :: new ( ) ;
552+ let arena = TypedArena :: default ( ) ;
561553 for _ in 0 ..100000 {
562554 arena. alloc ( Point { x : 1 , y : 2 , z : 3 } ) ;
563555 }
564556 }
565557
566558 #[ bench]
567559 pub fn bench_copy ( b : & mut Bencher ) {
568- let arena = TypedArena :: new ( ) ;
560+ let arena = TypedArena :: default ( ) ;
569561 b. iter ( || arena. alloc ( Point { x : 1 , y : 2 , z : 3 } ) )
570562 }
571563
@@ -584,7 +576,7 @@ mod tests {
584576
585577 #[ test]
586578 pub fn test_noncopy ( ) {
587- let arena = TypedArena :: new ( ) ;
579+ let arena = TypedArena :: default ( ) ;
588580 for _ in 0 ..100000 {
589581 arena. alloc ( Noncopy {
590582 string : "hello world" . to_string ( ) ,
@@ -595,15 +587,15 @@ mod tests {
595587
596588 #[ test]
597589 pub fn test_typed_arena_zero_sized ( ) {
598- let arena = TypedArena :: new ( ) ;
590+ let arena = TypedArena :: default ( ) ;
599591 for _ in 0 ..100000 {
600592 arena. alloc ( ( ) ) ;
601593 }
602594 }
603595
604596 #[ test]
605597 pub fn test_typed_arena_clear ( ) {
606- let mut arena = TypedArena :: new ( ) ;
598+ let mut arena = TypedArena :: default ( ) ;
607599 for _ in 0 ..10 {
608600 arena. clear ( ) ;
609601 for _ in 0 ..10000 {
@@ -628,7 +620,7 @@ mod tests {
628620 fn test_typed_arena_drop_count ( ) {
629621 let counter = Cell :: new ( 0 ) ;
630622 {
631- let arena: TypedArena < DropCounter > = TypedArena :: new ( ) ;
623+ let arena: TypedArena < DropCounter > = TypedArena :: default ( ) ;
632624 for _ in 0 ..100 {
633625 // Allocate something with drop glue to make sure it doesn't leak.
634626 arena. alloc ( DropCounter { count : & counter } ) ;
@@ -640,7 +632,7 @@ mod tests {
640632 #[ test]
641633 fn test_typed_arena_drop_on_clear ( ) {
642634 let counter = Cell :: new ( 0 ) ;
643- let mut arena: TypedArena < DropCounter > = TypedArena :: new ( ) ;
635+ let mut arena: TypedArena < DropCounter > = TypedArena :: default ( ) ;
644636 for i in 0 ..10 {
645637 for _ in 0 ..100 {
646638 // Allocate something with drop glue to make sure it doesn't leak.
@@ -667,7 +659,7 @@ mod tests {
667659 fn test_typed_arena_drop_small_count ( ) {
668660 DROP_COUNTER . with ( |c| c. set ( 0 ) ) ;
669661 {
670- let arena: TypedArena < SmallDroppable > = TypedArena :: new ( ) ;
662+ let arena: TypedArena < SmallDroppable > = TypedArena :: default ( ) ;
671663 for _ in 0 ..100 {
672664 // Allocate something with drop glue to make sure it doesn't leak.
673665 arena. alloc ( SmallDroppable ) ;
@@ -679,7 +671,7 @@ mod tests {
679671
680672 #[ bench]
681673 pub fn bench_noncopy ( b : & mut Bencher ) {
682- let arena = TypedArena :: new ( ) ;
674+ let arena = TypedArena :: default ( ) ;
683675 b. iter ( || {
684676 arena. alloc ( Noncopy {
685677 string : "hello world" . to_string ( ) ,
0 commit comments