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

Function slice_insert

cranelift/bforest/src/lib.rs:116–121  ·  view source on GitHub ↗

Insert `x` into `s` at position `i`, pushing out the last element.

(s: &mut [T], i: usize, x: T)

Source from the content-addressed store, hash-verified

114
115/// Insert `x` into `s` at position `i`, pushing out the last element.
116fn slice_insert<T: Copy>(s: &mut [T], i: usize, x: T) {
117 for j in (i + 1..s.len()).rev() {
118 s[j] = s[j - 1];
119 }
120 s[i] = x;
121}
122
123/// Shift elements in `s` to the left by `n` positions.
124fn slice_shift<T: Copy>(s: &mut [T], n: usize) {

Callers 4

slice_insertionFunction · 0.85
split_and_insertMethod · 0.85
try_inner_insertMethod · 0.85
try_leaf_insertMethod · 0.85

Calls 1

lenMethod · 0.45

Tested by 1

slice_insertionFunction · 0.68