File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 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> {
224224 unsafe {
225225 // Clear the last chunk, which is partially filled.
226226 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 ( ) {
228228 self . clear_last_chunk ( & mut last_chunk) ;
229+ let len = chunks_borrow. len ( ) ;
229230 // 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 ) {
231232 let cap = chunk. storage . cap ( ) ;
232233 chunk. destroy ( cap) ;
233234 }
234- chunks_borrow. push ( last_chunk) ;
235235 }
236236 }
237237 }
@@ -604,6 +604,15 @@ mod tests {
604604 }
605605 }
606606
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+
607616 // Drop tests
608617
609618 struct DropCounter < ' a > {
You can’t perform that action at this time.
0 commit comments