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 CommonPrefixLength for SetOf sort validation #75851

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ internal static int Compare(ReadOnlySpan<byte> x, ReadOnlySpan<byte> y)
int min = Math.Min(x.Length, y.Length);
int diff;

#if NET7_0_OR_GREATER
int diffIndex = x.CommonPrefixLength(y);
vcsjones marked this conversation as resolved.
Show resolved Hide resolved

if (diffIndex != min)
{
return (int)x[diffIndex] - y[diffIndex];
}
#else
for (int i = 0; i < min; i++)
{
int xVal = x[i];
Expand All @@ -28,6 +36,7 @@ internal static int Compare(ReadOnlySpan<byte> x, ReadOnlySpan<byte> y)
return diff;
}
}
#endif

// The sorting rules (T-REC-X.690-201508 sec 11.6) say that the shorter one
// counts as if it are padded with as many 0x00s on the right as required for
Expand Down