Use more `ReadOnlySpan<byte>`s in `System.Reflection.MetadataLoadContext` (#56207)
authorTheodore Tsirpanis <12659251+teo-tsirpanis@users.noreply.github.com>
Mon, 26 Jul 2021 15:41:50 +0000 (18:41 +0300)
committerGitHub <noreply@github.com>
Mon, 26 Jul 2021 15:41:50 +0000 (11:41 -0400)
commitb00a64a18c29543552a333ae8049006411d760ef
treed36fbfb17203a634ab1e886bd5d4b7f0ca4b77bb
parent567e7c33828705ff8da88db3bf29b454cd503add
Use more `ReadOnlySpan<byte>`s in `System.Reflection.MetadataLoadContext` (#56207)

* Use spans instead of byte arrays in `MetadataLoadContext.Utf8Constants`.

* Optimize Helpers.ToUtf16(ReadOnlySpan<byte>).

It avoids a byte array allocation on all frameworks.
And remove an unused overload of it.

* Address PR feedback.

* Fix ArgumentNullExceptions.
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/CoreType.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/CoreTypes.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Ecma/EcmaSignatureTypeProviderForToString.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Helpers.cs
src/libraries/System.Reflection.MetadataLoadContext/src/System/Reflection/TypeLoading/General/Utf8Constants.cs