Avoid temporary allocations during function context initialization (#217)
* Avoid temporary allocation when push locals during function invocation. * Extend value stack for all locals at once.
This commit is contained in:
parent
f19e1c27fc
commit
d2ea44e37c
|
@ -1289,14 +1289,8 @@ impl FunctionContext {
|
||||||
debug_assert!(!self.is_initialized);
|
debug_assert!(!self.is_initialized);
|
||||||
|
|
||||||
let num_locals = locals.iter().map(|l| l.count() as usize).sum();
|
let num_locals = locals.iter().map(|l| l.count() as usize).sum();
|
||||||
let locals = vec![Default::default(); num_locals];
|
|
||||||
|
|
||||||
// TODO: Replace with extend.
|
value_stack.extend(num_locals)?;
|
||||||
for local in locals {
|
|
||||||
value_stack
|
|
||||||
.push(local)
|
|
||||||
.map_err(|_| TrapKind::StackOverflow)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.is_initialized = true;
|
self.is_initialized = true;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1442,6 +1436,18 @@ impl ValueStack {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extend(&mut self, len: usize) -> Result<(), TrapKind> {
|
||||||
|
let cells = self
|
||||||
|
.buf
|
||||||
|
.get_mut(self.sp..self.sp + len)
|
||||||
|
.ok_or_else(|| TrapKind::StackOverflow)?;
|
||||||
|
for cell in cells {
|
||||||
|
*cell = Default::default();
|
||||||
|
}
|
||||||
|
self.sp += len;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn len(&self) -> usize {
|
fn len(&self) -> usize {
|
||||||
self.sp
|
self.sp
|
||||||
|
|
Loading…
Reference in New Issue