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

Method decode_in_place

src/ext/arrayvec.rs:78–102  ·  view source on GitHub ↗
(&mut self, out: &mut MaybeUninit<ArrayString<N>>)

Source from the content-addressed store, hash-verified

76impl<'a, const N: usize> Decoder<'a, ArrayString<N>> for ArrayStringDecoder<'a, N> {
77 #[inline(always)]
78 fn decode_in_place(&mut self, out: &mut MaybeUninit<ArrayString<N>>) {
79 let s: &str = self.0.decode();
80 let array_string = out.write(ArrayString::new());
81
82 // Avoid copying lots of memory for 1 byte strings.
83 // TODO miri doesn't like ArrayString::as_mut_str().as_mut_ptr(), replace with ArrayString::as_mut_ptr() when available.
84 if N > 64 || cfg!(miri) {
85 // Safety: We've ensured `self.lengths.max_len() <= N` in populate.
86 unsafe { array_string.try_push_str(s).unwrap_unchecked() };
87 return;
88 }
89 // Empty s points to no valid bytes, so we can't unsafe_wild_copy.
90 if s.is_empty() {
91 return;
92 }
93 // Safety: We just checked n != 0 and ensured `self.lengths.max_len() <= N` in populate.
94 // Also, `dst` has room for `[u8; N]` since it's an ArrayString<N>.
95 unsafe {
96 let src = s.as_ptr();
97 let dst = array_string.as_mut_str().as_mut_ptr();
98 let n = s.len();
99 unsafe_wild_copy!([u8; N], src, dst, n);
100 array_string.set_len(s.len());
101 }
102 }
103}
104impl<'a, const N: usize> Decode<'a> for ArrayString<N> {
105 type Decoder = ArrayStringDecoder<'a, N>;

Callers

nothing calls this directly

Calls 4

as_ptrMethod · 0.80
decodeMethod · 0.45
writeMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected