Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use helpers in Guid's ROS<byte> constructor #78446

Merged
merged 5 commits into from
Nov 21, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/libraries/System.Private.CoreLib/src/System/Guid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Guid(ReadOnlySpan<byte> b)
{
if (b.Length != 16)
{
throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "16"), nameof(b));
ThrowArgumentException();
}

if (BitConverter.IsLittleEndian)
DaZombieKiller marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -60,7 +60,7 @@ public Guid(ReadOnlySpan<byte> b)
}

// slower path for BigEndian:
_k = b[15]; // hoist bounds checks
_k = b[15]; // hoist bounds checks
DaZombieKiller marked this conversation as resolved.
Show resolved Hide resolved
_a = BinaryPrimitives.ReadInt32LittleEndian(b);
_b = BinaryPrimitives.ReadInt16LittleEndian(b.Slice(4));
_c = BinaryPrimitives.ReadInt16LittleEndian(b.Slice(6));
Expand All @@ -71,6 +71,11 @@ public Guid(ReadOnlySpan<byte> b)
_h = b[12];
_i = b[13];
_j = b[14];

static void ThrowArgumentException()
DaZombieKiller marked this conversation as resolved.
Show resolved Hide resolved
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
{
throw new ArgumentException(SR.Format(SR.Arg_GuidArrayCtor, "16"), nameof(b));
}
}

[CLSCompliant(false)]
Expand Down