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

Method insert

cranelift/entity/src/list.rs:530–545  ·  view source on GitHub ↗

Inserts an element as position `index` in the list, shifting all elements after it to the right.

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

Source from the content-addressed store, hash-verified

528 /// Inserts an element as position `index` in the list, shifting all elements after it to the
529 /// right.
530 pub fn insert(&mut self, index: usize, element: T, pool: &mut ListPool<T>) {
531 // Increase size by 1.
532 self.push(element, pool);
533
534 // Move tail elements.
535 let seq = self.as_mut_slice(pool);
536 if index < seq.len() {
537 let tail = &mut seq[index..];
538 for i in (1..tail.len()).rev() {
539 tail[i] = tail[i - 1];
540 }
541 tail[0] = element;
542 } else {
543 debug_assert_eq!(index, seq.len());
544 }
545 }
546
547 /// Removes the last element from the list.
548 fn remove_last(&mut self, len: usize, pool: &mut ListPool<T>) {

Callers 1

insert_removeFunction · 0.45

Calls 3

pushMethod · 0.45
as_mut_sliceMethod · 0.45
lenMethod · 0.45

Tested by 1

insert_removeFunction · 0.36