Skip to content

Commit

Permalink
Remove ReadGuidLittleEndian helper
Browse files Browse the repository at this point in the history
  • Loading branch information
DaZombieKiller committed Nov 16, 2022
1 parent 22338d2 commit 65763ac
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/libraries/System.Private.CoreLib/src/System/Guid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,28 @@ public Guid(ReadOnlySpan<byte> b)
ThrowArgumentException();
}

this = BitConverter.IsLittleEndian ? MemoryMarshal.Read<Guid>(b) : ReadGuidLittleEndian(b);

static void ThrowArgumentException()
if (BitConverter.IsLittleEndian)
{
throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "16"), nameof(b));
this = MemoryMarshal.Read<Guid>(b);
return;
}

// slower path for BigEndian:
static Guid ReadGuidLittleEndian(ReadOnlySpan<byte> b)
{
// hoist bounds checks
byte k = b[15];

return new Guid(
BinaryPrimitives.ReadInt32LittleEndian(b),
BinaryPrimitives.ReadInt16LittleEndian(b.Slice(4)),
BinaryPrimitives.ReadInt16LittleEndian(b.Slice(6)),
b[8],
b[9],
b[10],
b[11],
b[12],
b[13],
b[14],
k
);
_k = b[15]; // hoist bounds checks
_a = BinaryPrimitives.ReadInt32LittleEndian(b);
_b = BinaryPrimitives.ReadInt16LittleEndian(b.Slice(4));
_c = BinaryPrimitives.ReadInt16LittleEndian(b.Slice(6));
_d = b[8];
_e = b[9];
_f = b[10];
_g = b[11];
_h = b[12];
_i = b[13];
_j = b[14];

static void ThrowArgumentException()
{
throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "16"), nameof(b));
}
}

Expand Down

0 comments on commit 65763ac

Please sign in to comment.