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

Method truncate

cranelift/entity/src/list.rs:600–626  ·  view source on GitHub ↗

Shortens the list down to `len` elements. Does nothing if the list is already shorter than `len`.

(&mut self, new_len: usize, pool: &mut ListPool<T>)

Source from the content-addressed store, hash-verified

598 ///
599 /// Does nothing if the list is already shorter than `len`.
600 pub fn truncate(&mut self, new_len: usize, pool: &mut ListPool<T>) {
601 if new_len == 0 {
602 self.clear(pool);
603 return;
604 }
605
606 match pool.len_of(self) {
607 None => return,
608 Some(len) => {
609 if len <= new_len {
610 return;
611 }
612
613 let block;
614 let idx = self.index as usize;
615 let sclass = sclass_for_length(len);
616 let new_sclass = sclass_for_length(new_len);
617 if sclass != new_sclass {
618 block = pool.realloc(idx - 1, sclass, new_sclass, new_len + 1);
619 self.index = (block + 1) as u32;
620 } else {
621 block = idx - 1;
622 }
623 pool.data[block] = T::new(new_len);
624 }
625 }
626 }
627
628 /// Grow the list by inserting `count` elements at `index`.
629 ///

Callers 13

pop_frameMethod · 0.45
truncate_last_branchMethod · 0.45
optimize_branchesMethod · 0.45
clearMethod · 0.45
optimize_pure_enodeMethod · 0.45
process_elab_stackMethod · 0.45
truncateFunction · 0.45
resetMethod · 0.45
drop_lastMethod · 0.45
mainFunction · 0.45

Calls 5

sclass_for_lengthFunction · 0.85
len_ofMethod · 0.80
newFunction · 0.50
clearMethod · 0.45
reallocMethod · 0.45

Tested by 2

truncateFunction · 0.36
spawnMethod · 0.36