(&mut self, t: &ArrayString<N>)
| 10 | impl<const N: usize> Encoder<ArrayString<N>> for StrEncoder { |
| 11 | #[inline(always)] |
| 12 | fn encode(&mut self, t: &ArrayString<N>) { |
| 13 | // Only lengths < 255 are fast to encode and avoid copying lots of memory for 1 byte strings. |
| 14 | // TODO miri doesn't like ArrayString::as_str().as_ptr(), replace with ArrayString::as_ptr() when available. |
| 15 | if N > 64 || cfg!(miri) { |
| 16 | self.encode(t.as_str()); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | let s = t.as_str(); |
| 21 | self.0.lengths.encode_less_than_255(s.len()); |
| 22 | let primitives = self.0.elements.as_primitive().unwrap(); |
| 23 | primitives.reserve(N); // TODO Buffer::reserve impl additional * N so we can remove encode_vectored impl. |
| 24 | let dst = primitives.end_ptr(); |
| 25 | |
| 26 | // Safety: `s.as_ptr()` points to `N` valid bytes since it's referencing an ArrayString<N>. |
| 27 | // `dst` has enough space for `[T; N]` because we've reserved `N`. |
| 28 | unsafe { |
| 29 | *(dst as *mut MaybeUninit<[u8; N]>) = *(s.as_ptr() as *const MaybeUninit<[u8; N]>); |
| 30 | primitives.set_end_ptr(dst.add(s.len())); |
| 31 | } |
| 32 | } |
| 33 | #[inline(never)] |
| 34 | fn encode_vectored<'a>(&mut self, i: impl Iterator<Item = &'a ArrayString<N>> + Clone) { |
| 35 | // Only lengths < 255 are fast to encode and avoid copying lots of memory for 1 byte strings. |
nothing calls this directly
no test coverage detected