1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00

[release/9.0] Fix IndexOf Optimization Code (#108562)

* Fix IndexOf Optimization Code

* small typo

* Address the feedback

* Exclude hybrid globalization runs on the new added tests

---------

Co-authored-by: Tarek Mahmoud Sayed <tarekms@microsoft.com>
This commit is contained in:
github-actions[bot] 2024-10-07 08:16:11 -07:00 committed by GitHub
parent 48dfbed76e
commit 09393c29fa
Signed by: github
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 0 deletions

View file

@ -130,12 +130,14 @@ namespace System.Globalization
}
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
@ -144,6 +146,7 @@ namespace System.Globalization
// 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;
}
@ -192,6 +195,12 @@ namespace System.Globalization
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:
@ -246,12 +255,14 @@ namespace System.Globalization
}
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
@ -260,6 +271,7 @@ namespace System.Globalization
// 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;
}
@ -297,6 +309,12 @@ namespace System.Globalization
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:

View file

@ -127,6 +127,16 @@ namespace System.Globalization.Tests
yield return new object[] { s_currentCompare, "\u0130", "\u0131", 0, 1, CompareOptions.Ordinal, -1, 0 };
yield return new object[] { s_currentCompare, "\u0131", "\u0130", 0, 1, CompareOptions.Ordinal, -1, 0 };
if (!PlatformDetection.IsHybridGlobalizationOnBrowser)
{
yield return new object[] { s_invariantCompare, "est", "est", 0, 2, CompareOptions.IgnoreCase, 0, 2 };
yield return new object[] { s_invariantCompare, " est", "est", 0, 3, CompareOptions.IgnoreCase, 1, 2 };
yield return new object[] { s_invariantCompare, " st", "st", 0, 2, CompareOptions.IgnoreCase, 1, 1 };
yield return new object[] { s_invariantCompare, "est", "est", 0, 3, CompareOptions.IgnoreCase, 0, 3 };
yield return new object[] { s_invariantCompare, " est", "est", 0, 4, CompareOptions.IgnoreCase, 1, 3 };
yield return new object[] { s_invariantCompare, " st", "st", 0, 3, CompareOptions.IgnoreCase, 1, 2 };
}
// Platform differences
if (PlatformDetection.IsNlsGlobalization)
{