Optimize Memory<T> to ReadOnlyMemory<T> cast (#14309)
authorStephen Toub <stoub@microsoft.com>
Tue, 3 Oct 2017 20:59:31 +0000 (16:59 -0400)
committerGitHub <noreply@github.com>
Tue, 3 Oct 2017 20:59:31 +0000 (16:59 -0400)
commit895a755d090ff04ed2e043e851dadc1c30f0cb35
tree6285560f7d320f6b7532f6d9d1681c82151f2205
parent32bb7e16d5b741c12ed2388d44b5d736ae0ab240
Optimize Memory<T> to ReadOnlyMemory<T> cast (#14309)

They have the same layout; we can just use Unsafe.As.  In a microbenchmark that just repeatedly reads from a `Memory<byte>` field and writes it to a `ReadOnlyMemory<byte>` field, this doubles throughput.
src/mscorlib/shared/System/Memory.cs
src/mscorlib/shared/System/ReadOnlyMemory.cs