Skip to content

Commit

Permalink
do not recycle empty dummy stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Jan 4, 2023
1 parent 9864fce commit df8a182
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/wasmi/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl EngineStacks {

/// Disose and recycle the `stack`.
pub fn recycle(&mut self, stack: Stack) {
if self.stacks.len() < self.keep {
if !stack.is_empty() && self.stacks.len() < self.keep {
self.stacks.push(stack);
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/wasmi/src/engine/stack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ impl Stack {
}
}

/// Returns `true` if the [`Stack`] is empty.
///
/// # Note
///
/// Empty [`Stack`] instances are usually non-usable dummy instances.
pub(crate) fn is_empty(&self) -> bool {
self.values.is_empty()
}

/// Push the given `frame` onto the call stack.
///
/// # Note
Expand Down
5 changes: 5 additions & 0 deletions crates/wasmi/src/engine/stack/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ impl ValueStack {
}
}

/// Returns `true` if the [`ValueStack`] is empty.
pub fn is_empty(&self) -> bool {
self.entries.capacity() == 0
}

/// Creates a new empty [`ValueStack`].
///
/// # Panics
Expand Down

0 comments on commit df8a182

Please sign in to comment.