Open
Description
I have a [u8; 4]
and I want to copy an unknown number of bytes from it into a &mut [u8]
. Based on benchmarking, on x86_64 at least it is much slower to call memcpy
than it is to do a byte-by-byte copy. The fastest implementation of this pattern in Rust is this:
if len > 4 {
core::hint::unreachable_unchecked();
}
for i in 0..len {
*dst.get_unchecked_mut(i) = src[i];
}
That just doesn't seem right to me.