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) (JIT: boost inlining for methods that may return small arrays #114806) - Escape Analysis for non-captured Span (JIT: enhance escape analysis to understand local struct fields #113977)
- Make this work in R2R as well
- Verify this works propery in Tier1+instr
cc @AndyAyersMS