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

[release/8.0-staging] Tweak Invariant IndexOf logic #108729

Merged
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 @@ -130,14 +130,12 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
}

int startIndex, endIndex, jump;
ReadOnlySpan<char> remainingSource;
if (fromBeginning)
{
// Left to right, from zero to last possible index in the source string.
// Incrementing by one after each iteration. Stop condition is last possible index plus 1.
startIndex = 0;
endIndex = source.Length - target.Length + 1;
remainingSource = source.Slice(endIndex);
jump = 1;
}
else
Expand All @@ -146,7 +144,6 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
// Decrementing by one after each iteration. Stop condition is last possible index minus 1.
startIndex = source.Length - target.Length;
endIndex = -1;
remainingSource = source.Slice(0, startIndex);
jump = -1;
}

Expand Down Expand Up @@ -196,6 +193,10 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
}

// Before we return -1, check if the remaining source contains any special or non-Ascii characters.
ReadOnlySpan<char> remainingSource = fromBeginning
? source.Slice(endIndex)
: source.Slice(0, startIndex);

if (remainingSource.ContainsAnyExcept(s_nonSpecialAsciiChars))
{
goto InteropCall;
Expand Down Expand Up @@ -252,14 +253,12 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
}

int startIndex, endIndex, jump;
ReadOnlySpan<char> remainingSource;
if (fromBeginning)
{
// Left to right, from zero to last possible index in the source string.
// Incrementing by one after each iteration. Stop condition is last possible index plus 1.
startIndex = 0;
endIndex = source.Length - target.Length + 1;
remainingSource = source.Slice(endIndex);
jump = 1;
}
else
Expand All @@ -268,7 +267,6 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
// Decrementing by one after each iteration. Stop condition is last possible index minus 1.
startIndex = source.Length - target.Length;
endIndex = -1;
remainingSource = source.Slice(0, startIndex);
jump = -1;
}

Expand Down Expand Up @@ -306,12 +304,6 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
Next: ;
}

// Before we return -1, check if the remaining source contains any special or non-Ascii characters.
if (remainingSource.ContainsAnyExcept(s_nonSpecialAsciiChars))
{
goto InteropCall;
}

return -1;

InteropCall:
Expand Down
Loading