Skip to content

Commit

Permalink
Track element count only for types that need drop
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Oct 20, 2020
1 parent a85e949 commit 2705cae
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/rustc_arena/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,12 @@ impl<T> TypedArena<T> {
let mut chunks = self.chunks.borrow_mut();
let mut new_cap;
if let Some(last_chunk) = chunks.last_mut() {
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
last_chunk.entries = used_bytes / mem::size_of::<T>();
// If a type is `!needs_drop`, we don't need to keep track of how many elements
// the chunk stores - the field will be ignored anyway.
if mem::needs_drop::<T>() {
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
last_chunk.entries = used_bytes / mem::size_of::<T>();
}

// If the previous chunk's len is less than HUGE_PAGE
// bytes, then this chunk will be least double the previous
Expand Down

0 comments on commit 2705cae

Please sign in to comment.