File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -224,14 +224,14 @@ impl<T> TypedArena<T> {
224
224
unsafe {
225
225
// Clear the last chunk, which is partially filled.
226
226
let mut chunks_borrow = self . chunks . borrow_mut ( ) ;
227
- if let Some ( mut last_chunk) = chunks_borrow. pop ( ) {
227
+ if let Some ( mut last_chunk) = chunks_borrow. last_mut ( ) {
228
228
self . clear_last_chunk ( & mut last_chunk) ;
229
+ let len = chunks_borrow. len ( ) ;
229
230
// If `T` is ZST, code below has no effect.
230
- for mut chunk in chunks_borrow. drain ( ..) {
231
+ for mut chunk in chunks_borrow. drain ( ..len- 1 ) {
231
232
let cap = chunk. storage . cap ( ) ;
232
233
chunk. destroy ( cap) ;
233
234
}
234
- chunks_borrow. push ( last_chunk) ;
235
235
}
236
236
}
237
237
}
@@ -604,6 +604,15 @@ mod tests {
604
604
}
605
605
}
606
606
607
+ #[ bench]
608
+ pub fn bench_typed_arena_clear ( b : & mut Bencher ) {
609
+ let mut arena = TypedArena :: default ( ) ;
610
+ b. iter ( || {
611
+ arena. alloc ( Point { x : 1 , y : 2 , z : 3 } ) ;
612
+ arena. clear ( ) ;
613
+ } )
614
+ }
615
+
607
616
// Drop tests
608
617
609
618
struct DropCounter < ' a > {
You can’t perform that action at this time.
0 commit comments