Skip to content

Commit

Permalink
fix: take currently free slots into account
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Oct 21, 2023
1 parent 04f5c43 commit 02c5d60
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ impl<T> Arena<T> {
}

/// Reserve capacity for at least `additional` more elements to be inserted
#[inline(always)]
pub fn reserve(&mut self, additional: usize) {
self.storage.reserve(additional)
let currently_free = self.storage.len().saturating_sub(self.len as usize);
let to_reserve = additional.saturating_sub(currently_free);
self.storage.reserve(to_reserve);
}

/// Returns whether the arena is empty.
Expand Down

0 comments on commit 02c5d60

Please sign in to comment.