From 4359bf624a43eed51b1ce33ce39b627d30e8b56b Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Mon, 26 Dec 2022 14:06:56 +0100 Subject: [PATCH] Use IndexOfAnyValues in CompareInfo.Icu --- .../System/Globalization/CompareInfo.Icu.cs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs index 445d82c548b97..d4363b3ad1670 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Icu.cs @@ -11,6 +11,11 @@ namespace System.Globalization { public partial class CompareInfo { + // Characters which require special handling are those in [0x00, 0x1F] and [0x7F, 0xFFFF] except \t\v\f + // Matches HighCharTable below. + private static readonly IndexOfAnyValues s_nonSpecialAsciiChars = + IndexOfAnyValues.Create("\t\v\f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + [NonSerialized] private bool _isAsciiEqualityOrdinal; @@ -99,21 +104,18 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan source, Rea char* a = ap; char* b = bp; - for (int j = 0; j < target.Length; j++) + if (target.IndexOfAnyExcept(s_nonSpecialAsciiChars) >= 0) { - char targetChar = *(b + j); - if (targetChar >= 0x80 || HighCharTable[targetChar]) - goto InteropCall; + goto InteropCall; } if (target.Length > source.Length) { - for (int k = 0; k < source.Length; k++) + if (source.IndexOfAnyExcept(s_nonSpecialAsciiChars) >= 0) { - char targetChar = *(a + k); - if (targetChar >= 0x80 || HighCharTable[targetChar]) - goto InteropCall; + goto InteropCall; } + return -1; } @@ -203,21 +205,18 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan source, ReadOnlySpan< char* a = ap; char* b = bp; - for (int j = 0; j < target.Length; j++) + if (target.IndexOfAnyExcept(s_nonSpecialAsciiChars) >= 0) { - char targetChar = *(b + j); - if (targetChar >= 0x80 || HighCharTable[targetChar]) - goto InteropCall; + goto InteropCall; } if (target.Length > source.Length) { - for (int k = 0; k < source.Length; k++) + if (source.IndexOfAnyExcept(s_nonSpecialAsciiChars) >= 0) { - char targetChar = *(a + k); - if (targetChar >= 0x80 || HighCharTable[targetChar]) - goto InteropCall; + goto InteropCall; } + return -1; }