MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / lower_map

Function lower_map

crates/wasmtime/src/runtime/component/values.rs:1115–1142  ·  view source on GitHub ↗

Lower a map as list > with the specified key and value types.

(
    cx: &mut LowerContext<'_, T>,
    map_ty: &TypeMap,
    pairs: &[(Val, Val)],
)

Source from the content-addressed store, hash-verified

1113
1114/// Lower a map as list<tuple<k, v>> with the specified key and value types.
1115fn lower_map<T>(
1116 cx: &mut LowerContext<'_, T>,
1117 map_ty: &TypeMap,
1118 pairs: &[(Val, Val)],
1119) -> Result<(usize, usize)> {
1120 let key_type = map_ty.key;
1121 let value_type = map_ty.value;
1122 let value_offset = usize::try_from(map_ty.value_offset32).unwrap();
1123 let tuple_align = map_ty.entry_abi.align32;
1124 let tuple_size = usize::try_from(map_ty.entry_abi.size32).unwrap();
1125
1126 let size = pairs
1127 .len()
1128 .checked_mul(tuple_size)
1129 .ok_or_else(|| crate::format_err!("size overflow copying a map"))?;
1130 let ptr = cx.realloc(0, 0, tuple_align, size)?;
1131
1132 let mut tuple_ptr = ptr;
1133 for (key, value) in pairs {
1134 // Store key at tuple_ptr
1135 key.store(cx, key_type, tuple_ptr)?;
1136 // Store value at tuple_ptr + value_offset (properly aligned)
1137 value.store(cx, value_type, tuple_ptr + value_offset)?;
1138 tuple_ptr += tuple_size;
1139 }
1140
1141 Ok((ptr, pairs.len()))
1142}
1143
1144fn push_flags(ty: &TypeFlags, flags: &mut Vec<String>, mut offset: u32, mut bits: u32) {
1145 while bits > 0 && usize::try_from(offset).unwrap() < ty.names.len() {

Callers 2

lowerMethod · 0.85
storeMethod · 0.85

Calls 6

OkFunction · 0.85
checked_mulMethod · 0.80
unwrapMethod · 0.45
lenMethod · 0.45
reallocMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected