Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

perf(wave): avoid Vec allocation in make_tuple (#12464)

phrwlk5bdb78b3bcf8
diff --git a/crates/wasmtime/src/runtime/wave/core.rs b/crates/wasmtime/src/runtime/wave/core.rs
index fd89da83d7..a90eb21fff 100644
--- a/crates/wasmtime/src/runtime/wave/core.rs
+++ b/crates/wasmtime/src/runtime/wave/core.rs
@@ -70,11 +70,16 @@ impl WasmValue for crate::Val {
));
}
}
- let [l_val, h_val]: [Self; 2] = vals
- .into_iter()
- .collect::<Vec<_>>()
- .try_into()
- .map_err(|_| WasmValueError::Other("expected 2 values".to_string()))?;
+ let mut iter = vals.into_iter();
+ let Some(l_val) = iter.next() else {
+ return Err(WasmValueError::Other("expected 2 values".to_string()));
+ };
+ let Some(h_val) = iter.next() else {
+ return Err(WasmValueError::Other("expected 2 values".to_string()));
+ };
+ if iter.next().is_some() {
+ return Err(WasmValueError::Other("expected 2 values".to_string()));
+ }
let (Some(l), Some(h)) = (l_val.i64(), h_val.i64()) else {
return Err(WasmValueError::Other("expected 2 i64s (v64x2)".to_string()));