Skip to content

Commit 504c7eb

Browse files
committed
Remove unnecessary clone of map pairs during lowering
Val::Map already holds Vec<(Val, Val)> which derefs to &[(Val, Val)], matching lower_map's signature directly. The intermediate Vec allocation and deep clone of every key/value pair was redundant.
1 parent db1f816 commit 504c7eb

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

  • crates/wasmtime/src/runtime/component

crates/wasmtime/src/runtime/component/values.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,9 @@ impl Val {
441441
Ok(())
442442
}
443443
(InterfaceType::List(_), _) => unexpected(ty, self),
444-
(InterfaceType::Map(ty), Val::Map(map)) => {
445-
// Maps are stored as list<tuple<k, v>> in canonical ABI
444+
(InterfaceType::Map(ty), Val::Map(pairs)) => {
446445
let map_ty = &cx.types[ty];
447-
// Convert HashMap to Vec<(Val, Val)> for lowering
448-
let pairs: Vec<(Val, Val)> =
449-
map.iter().map(|(k, v)| (k.clone(), v.clone())).collect();
450-
let (ptr, len) = lower_map(cx, map_ty.key, map_ty.value, &pairs)?;
446+
let (ptr, len) = lower_map(cx, map_ty.key, map_ty.value, pairs)?;
451447
next_mut(dst).write(ValRaw::i64(ptr as i64));
452448
next_mut(dst).write(ValRaw::i64(len as i64));
453449
Ok(())

0 commit comments

Comments
 (0)