Skip to content

Commit d3cb21d

Browse files
committed
re-design Sp::new constructor
1 parent 7aec9da commit d3cb21d

File tree

1 file changed

+5
-6
lines changed
  • crates/wasmi/src/engine/executor/handler

1 file changed

+5
-6
lines changed

crates/wasmi/src/engine/executor/handler/state.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,14 @@ pub struct Sp {
107107
value: *mut UntypedVal,
108108
}
109109

110-
impl<'a> From<&'a mut [UntypedVal]> for Sp {
111-
fn from(values: &'a mut [UntypedVal]) -> Self {
110+
impl Sp {
111+
pub fn new(cells: &mut Vec<UntypedVal>, start: usize) -> Self {
112+
debug_assert!(start < cells.len());
112113
Self {
113-
value: values.as_mut_ptr(),
114+
value: unsafe { cells.as_mut_ptr().add(start) },
114115
}
115116
}
116-
}
117117

118-
impl Sp {
119118
pub fn get<T>(self, slot: Slot) -> T
120119
where
121120
UntypedVal: ReadAs<T>,
@@ -235,7 +234,7 @@ impl ValueStack {
235234
}
236235

237236
fn sp(&mut self, start: usize) -> Sp {
238-
Sp::from(&mut self.cells[start..]) // TODO: maybe avoid bounds check if necessary for performance
237+
Sp::new(&mut self.cells, start)
239238
}
240239

241240
fn push(&mut self, start: usize, size: usize, len_params: u16) -> Result<Sp, TrapCode> {

0 commit comments

Comments
 (0)