MCPcopy Create free account
hub / github.com/SoftbearStudios/bitcode / get_mut_or_resize

Function get_mut_or_resize

src/serde/mod.rs:27–38  ·  view source on GitHub ↗
(vec: &mut Vec<T>, index: usize)

Source from the content-addressed store, hash-verified

25
26#[inline(always)]
27fn get_mut_or_resize<T: Default>(vec: &mut Vec<T>, index: usize) -> &mut T {
28 if index >= vec.len() {
29 #[cold]
30 #[inline(never)]
31 fn cold<T: Default>(vec: &mut Vec<T>, index: usize) {
32 vec.resize_with(index + 1, Default::default);
33 }
34 cold(vec, index);
35 }
36 // Safety we've just resized `vec.len()` to be > than `index`.
37 unsafe { vec.get_unchecked_mut(index) }
38}
39
40impl serde::ser::Error for Error {
41 fn custom<T>(t: T) -> Self

Callers 2

serialize_enumMethod · 0.85
populateMethod · 0.85

Calls 2

coldFunction · 0.85
lenMethod · 0.45

Tested by

no test coverage detected