diff --git a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/SetOfValueComparer.cs b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/SetOfValueComparer.cs index e85db7683c930..44b6c3030957e 100644 --- a/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/SetOfValueComparer.cs +++ b/src/libraries/System.Formats.Asn1/src/System/Formats/Asn1/SetOfValueComparer.cs @@ -17,6 +17,14 @@ internal static int Compare(ReadOnlySpan x, ReadOnlySpan y) int min = Math.Min(x.Length, y.Length); int diff; +#if NET7_0_OR_GREATER + int diffIndex = x.CommonPrefixLength(y); + + if (diffIndex != min) + { + return (int)x[diffIndex] - y[diffIndex]; + } +#else for (int i = 0; i < min; i++) { int xVal = x[i]; @@ -28,6 +36,7 @@ internal static int Compare(ReadOnlySpan x, ReadOnlySpan 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