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

Method resize

crates/core/src/alloc/vec.rs:173–192  ·  view source on GitHub ↗

Same as [`std::vec::Vec::resize`] but returns an error on allocation failure.

(&mut self, new_len: usize, value: T)

Source from the content-addressed store, hash-verified

171 /// Same as [`std::vec::Vec::resize`] but returns an error on allocation
172 /// failure.
173 pub fn resize(&mut self, new_len: usize, value: T) -> Result<(), OutOfMemory>
174 where
175 T: TryClone,
176 {
177 match new_len.cmp(&self.len()) {
178 Ordering::Less => self.truncate(new_len),
179 Ordering::Equal => {}
180 Ordering::Greater => {
181 let delta = new_len - self.len();
182 self.reserve(delta)?;
183 // Minimize `try_clone` calls by always pushing `value` directly
184 // as the last element.
185 for _ in 0..delta - 1 {
186 self.push(value.try_clone()?)?;
187 }
188 self.push(value)?;
189 }
190 }
191 Ok(())
192 }
193
194 /// Same as [`std::vec::Vec::resize_with`] but returns an error on
195 /// allocation failure.

Callers 4

grow_memoryMethod · 0.45
test_big_random_bufFunction · 0.45
wasm_mutateFunction · 0.45
try_vec_resizeFunction · 0.45

Calls 7

OkFunction · 0.85
cmpMethod · 0.45
lenMethod · 0.45
truncateMethod · 0.45
reserveMethod · 0.45
pushMethod · 0.45
try_cloneMethod · 0.45

Tested by 3

grow_memoryMethod · 0.36
test_big_random_bufFunction · 0.36
try_vec_resizeFunction · 0.36