Skip to content

Commit 02fa43d

Browse files
authored
Merge pull request #502 from Hywan/feat-api-function-avoid-cloning
feat(api) Avoid cloning `Vec<Type>` for each host function call
2 parents 028f59a + b4f5643 commit 02fa43d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/api/src/externals/function.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ impl Function {
165165
wasmer::RuntimeError::new(io::Error::from(error).to_string())
166166
})?;
167167

168-
let result_types = environment.result_types.clone();
168+
let result_types = &environment.result_types;
169169
let has_result_types = !result_types.is_empty();
170170

171171
Ok(if let Ok(results) = results.cast_as::<PyTuple>(py) {
172172
results
173173
.iter()
174174
.zip(result_types)
175-
.map(to_wasm_value)
175+
.map(|(value, ty)| to_wasm_value((value, *ty)))
176176
.collect::<PyResult<_>>()
177177
.map_err(|error| {
178178
wasmer::RuntimeError::new(io::Error::from(error).to_string())
@@ -205,8 +205,8 @@ impl Function {
205205
fn __call__<'p>(&self, py: Python<'p>, arguments: &PyTuple) -> PyResult<PyObject> {
206206
let arguments: Vec<wasmer::Value> = arguments
207207
.iter()
208-
.zip(self.inner.ty().params().iter().cloned())
209-
.map(to_wasm_value)
208+
.zip(self.inner.ty().params())
209+
.map(|(value, ty)| to_wasm_value((value, *ty)))
210210
.collect::<PyResult<_>>()?;
211211

212212
let results = self

0 commit comments

Comments
 (0)