mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-15 20:45:45 +03:00
arena: speed up TypedArena::clear
This commit is contained in:
+12
-3
@@ -224,14 +224,14 @@ pub fn clear(&mut self) {
|
||||
unsafe {
|
||||
// Clear the last chunk, which is partially filled.
|
||||
let mut chunks_borrow = self.chunks.borrow_mut();
|
||||
if let Some(mut last_chunk) = chunks_borrow.pop() {
|
||||
if let Some(mut last_chunk) = chunks_borrow.last_mut() {
|
||||
self.clear_last_chunk(&mut last_chunk);
|
||||
let len = chunks_borrow.len();
|
||||
// If `T` is ZST, code below has no effect.
|
||||
for mut chunk in chunks_borrow.drain(..) {
|
||||
for mut chunk in chunks_borrow.drain(..len-1) {
|
||||
let cap = chunk.storage.cap();
|
||||
chunk.destroy(cap);
|
||||
}
|
||||
chunks_borrow.push(last_chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -604,6 +604,15 @@ pub fn test_typed_arena_clear() {
|
||||
}
|
||||
}
|
||||
|
||||
#[bench]
|
||||
pub fn bench_typed_arena_clear(b: &mut Bencher) {
|
||||
let mut arena = TypedArena::default();
|
||||
b.iter(|| {
|
||||
arena.alloc(Point { x: 1, y: 2, z: 3 });
|
||||
arena.clear();
|
||||
})
|
||||
}
|
||||
|
||||
// Drop tests
|
||||
|
||||
struct DropCounter<'a> {
|
||||
|
||||
Reference in New Issue
Block a user