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

Method len_of

cranelift/entity/src/list.rs:177–186  ·  view source on GitHub ↗

Read the length of a list field, if it exists.

(&self, list: &EntityList<T>)

Source from the content-addressed store, hash-verified

175
176 /// Read the length of a list field, if it exists.
177 fn len_of(&self, list: &EntityList<T>) -> Option<usize> {
178 let idx = list.index as usize;
179 // `idx` points at the list elements. The list length is encoded in the element immediately
180 // before the list elements.
181 //
182 // The `wrapping_sub` handles the special case 0, which is the empty list. This way, the
183 // cost of the bounds check that we have to pay anyway is co-opted to handle the special
184 // case of the empty list.
185 self.data.get(idx.wrapping_sub(1)).map(|len| len.index())
186 }
187
188 /// Allocate a storage block with a size given by `sclass`.
189 ///

Callers 9

lenMethod · 0.80
is_validMethod · 0.80
as_sliceMethod · 0.80
as_mut_sliceMethod · 0.80
deep_cloneMethod · 0.80
clearMethod · 0.80
pushMethod · 0.80
growMethod · 0.80
truncateMethod · 0.80

Calls 3

mapMethod · 0.45
getMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected