Open
Description
JIT should be able to eliminate GC allocation in this snippet:
void Test(int value, Span<byte> dest) =>
BitConverter.GetBytes(value).AsSpan(0, 3).CopyTo(dest);
This pattern could be used as a safe alternative to "write N-bytes of a primitive to a span of bytes". Alternative zero-alloc patterns don't look pretty/involve unsafe
Sub-tasks:
- Mark Memmove as non-escaping (JIT: Mark certain intrinsics as non-escaping #113093)
- Make sure
BitConverter.GetBytes
is inlineable (it is not currently) - Escape Analysis for non-captured Span
cc @AndyAyersMS