@@ -11,6 +11,11 @@ namespace System.Globalization
1111{
1212 public partial class CompareInfo
1313 {
14+ // Characters which require special handling are those in [0x00, 0x1F] and [0x7F, 0xFFFF] except \t\v\f
15+ // Matches HighCharTable below.
16+ private static readonly IndexOfAnyValues < char > s_nonSpecialAsciiChars =
17+ IndexOfAnyValues . Create ( "\t \v \f !\" #$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\ ]^_`abcdefghijklmnopqrstuvwxyz{|}~" ) ;
18+
1419 [ NonSerialized ]
1520 private bool _isAsciiEqualityOrdinal ;
1621
@@ -99,21 +104,18 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
99104 char * a = ap ;
100105 char * b = bp ;
101106
102- for ( int j = 0 ; j < target . Length ; j ++ )
107+ if ( target . IndexOfAnyExcept ( s_nonSpecialAsciiChars ) > = 0 )
103108 {
104- char targetChar = * ( b + j ) ;
105- if ( targetChar >= 0x80 || HighCharTable [ targetChar ] )
106- goto InteropCall ;
109+ goto InteropCall ;
107110 }
108111
109112 if ( target . Length > source . Length )
110113 {
111- for ( int k = 0 ; k < source . Length ; k ++ )
114+ if ( source . IndexOfAnyExcept ( s_nonSpecialAsciiChars ) > = 0 )
112115 {
113- char targetChar = * ( a + k ) ;
114- if ( targetChar >= 0x80 || HighCharTable [ targetChar ] )
115- goto InteropCall ;
116+ goto InteropCall ;
116117 }
118+
117119 return - 1 ;
118120 }
119121
@@ -203,21 +205,18 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
203205 char * a = ap ;
204206 char * b = bp ;
205207
206- for ( int j = 0 ; j < target . Length ; j ++ )
208+ if ( target . IndexOfAnyExcept ( s_nonSpecialAsciiChars ) > = 0 )
207209 {
208- char targetChar = * ( b + j ) ;
209- if ( targetChar >= 0x80 || HighCharTable [ targetChar ] )
210- goto InteropCall ;
210+ goto InteropCall ;
211211 }
212212
213213 if ( target . Length > source . Length )
214214 {
215- for ( int k = 0 ; k < source . Length ; k ++ )
215+ if ( source . IndexOfAnyExcept ( s_nonSpecialAsciiChars ) > = 0 )
216216 {
217- char targetChar = * ( a + k ) ;
218- if ( targetChar >= 0x80 || HighCharTable [ targetChar ] )
219- goto InteropCall ;
217+ goto InteropCall ;
220218 }
219+
221220 return - 1 ;
222221 }
223222
0 commit comments