diff --git a/src/libraries/System.Private.CoreLib/src/System/Guid.cs b/src/libraries/System.Private.CoreLib/src/System/Guid.cs index b6946be5ec578b..911fb9f7184a30 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Guid.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Guid.cs @@ -841,10 +841,6 @@ private static bool IsHexPrefix(ReadOnlySpan str, int i) => str[i] == '0' && (str[i + 1] | 0x20) == 'x'; - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static unsafe ReadOnlySpan AsBytes(in Guid source) => - new ReadOnlySpan(Unsafe.AsPointer(ref Unsafe.AsRef(in source)), sizeof(Guid)); - // Returns an unsigned byte array containing the GUID. public byte[] ToByteArray() { @@ -856,7 +852,7 @@ public byte[] ToByteArray() else { // slower path for BigEndian - Guid guid = new Guid(AsBytes(this), false); + Guid guid = new Guid(MemoryMarshal.AsBytes(new ReadOnlySpan(in this)), false); MemoryMarshal.TryWrite(g, in guid); } return g; @@ -874,7 +870,7 @@ public byte[] ToByteArray(bool bigEndian) else { // slower path for Reverse - Guid guid = new Guid(AsBytes(this), bigEndian); + Guid guid = new Guid(MemoryMarshal.AsBytes(new ReadOnlySpan(in this)), bigEndian); MemoryMarshal.TryWrite(g, in guid); } return g; @@ -893,7 +889,7 @@ public bool TryWriteBytes(Span destination) else { // slower path for BigEndian - Guid guid = new Guid(AsBytes(this), false); + Guid guid = new Guid(MemoryMarshal.AsBytes(new ReadOnlySpan(in this)), false); MemoryMarshal.TryWrite(destination, in guid); } return true; @@ -915,7 +911,7 @@ public bool TryWriteBytes(Span destination, bool bigEndian, out int bytesW else { // slower path for Reverse - Guid guid = new Guid(AsBytes(this), bigEndian); + Guid guid = new Guid(MemoryMarshal.AsBytes(new ReadOnlySpan(in this)), bigEndian); MemoryMarshal.TryWrite(destination, in guid); } bytesWritten = 16;