Skip to content

Commit

Permalink
Use IndexOfAnyValues in CompareInfo.Icu (#79787)
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan authored Dec 30, 2022
1 parent fc881d5 commit 5b8ebea
Showing 1 changed file with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> s_nonSpecialAsciiChars =
IndexOfAnyValues.Create("\t\v\f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");

[NonSerialized]
private bool _isAsciiEqualityOrdinal;

Expand Down Expand Up @@ -99,21 +104,18 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> 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;
}

Expand Down Expand Up @@ -203,21 +205,18 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> 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;
}

Expand Down

0 comments on commit 5b8ebea

Please sign in to comment.