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

Method push

cranelift/entity/src/list.rs:389–418  ·  view source on GitHub ↗

Appends an element to the back of the list. Returns the index where the element was inserted.

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

Source from the content-addressed store, hash-verified

387 /// Appends an element to the back of the list.
388 /// Returns the index where the element was inserted.
389 pub fn push(&mut self, element: T, pool: &mut ListPool<T>) -> usize {
390 let idx = self.index as usize;
391 match pool.len_of(self) {
392 None => {
393 // This is an empty list. Allocate a block and set length=1.
394 debug_assert_eq!(idx, 0, "Invalid pool");
395 let block = pool.alloc(sclass_for_length(1));
396 pool.data[block] = T::new(1);
397 pool.data[block + 1] = element;
398 self.index = (block + 1) as u32;
399 0
400 }
401 Some(len) => {
402 // Do we need to reallocate?
403 let new_len = len + 1;
404 let block;
405 if is_sclass_min_length(new_len) {
406 // Reallocate, preserving length + all old elements.
407 let sclass = sclass_for_length(len);
408 block = pool.realloc(idx - 1, sclass, sclass + 1, len + 1);
409 self.index = (block + 1) as u32;
410 } else {
411 block = idx - 1;
412 }
413 pool.data[block + new_len] = element;
414 pool.data[block] = T::new(new_len);
415 len
416 }
417 }
418 }
419
420 /// Grow list by adding `count` reserved-value elements at the end.
421 ///

Callers 15

lineMethod · 0.45
line_with_locationMethod · 0.45
empty_lineMethod · 0.45
parse_multilineFunction · 0.45
import_functionMethod · 0.45
import_global_valueMethod · 0.45
write_function_addrMethod · 0.45
write_data_addrMethod · 0.45
declare_functionMethod · 0.45
declare_dataMethod · 0.45

Calls 6

sclass_for_lengthFunction · 0.85
is_sclass_min_lengthFunction · 0.85
len_ofMethod · 0.80
newFunction · 0.50
allocMethod · 0.45
reallocMethod · 0.45

Tested by 15

run_a_commandFunction · 0.36
get_isle_filesFunction · 0.36
test_rules_with_termFunction · 0.36
libcall_functionFunction · 0.36
libcall_functionFunction · 0.36
iterFunction · 0.36
iter_revFunction · 0.36
keysFunction · 0.36