Skip to content
Merged
Prev Previous commit
Next Next commit
Fixed bug and added tests for this
  • Loading branch information
gfoidl authored and github-actions committed Aug 17, 2022
commit d011202ab08a764efb376172af3a1b4c468522fd
4 changes: 4 additions & 0 deletions src/libraries/Common/tests/Tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4699,6 +4699,8 @@ public static void Remove_Invalid()
[InlineData("aaaAaaaaaaa", 'A', 'a', "aaaaaaaaaaa")]
// Single iteration of vectorised path; 3 remainders handled by vectorized path
[InlineData("AaaaaaaaaAa", 'A', 'a', "aaaaaaaaaaa")]
// Single iteration of vectorized path; 0 remainders handled by vectorized path
[InlineData("aaaaaaaaaAa", 'A', 'a', "aaaaaaaaaaa")]
// Eight chars before a match (copyLength > 0), single iteration of vectorized path for the remainder
[InlineData("12345678AAAAAAA", 'A', 'a', "12345678aaaaaaa")]
// ------------------------- For Vector<ushort>.Count == 16 (AVX2) -------------------------
Expand All @@ -4707,6 +4709,8 @@ public static void Remove_Invalid()
[InlineData("aaaAaaaaaaaAaaaaaaa", 'A', 'a', "aaaaaaaaaaaaaaaaaaa")]
// Single iteration of vectorised path; 3 remainders handled by vectorized path
[InlineData("AaaaaaaaAaaaaaaaaAa", 'A', 'a', "aaaaaaaaaaaaaaaaaaa")]
// Single iteration of vectorized path; 0 remainders handled by vectorized path
[InlineData("aaaaaaaaaaaaaaaaaAa", 'A', 'a', "aaaaaaaaaaaaaaaaaaa")]
// Sixteen chars before a match (copyLength > 0), single iteration of vectorized path for the remainder
[InlineData("1234567890123456AAAAAAAAAAAAAAA", 'A', 'a', "1234567890123456aaaaaaaaaaaaaaa")]
// ----------------------------------- General test data -----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ public string Replace(char oldChar, char newChar)

nuint lengthToExamine = remainingLength - (nuint)Vector<ushort>.Count;

if (lengthToExamine > 0)
if ((nint)lengthToExamine > 0)
{
do
{
Expand All @@ -1043,7 +1043,7 @@ public string Replace(char oldChar, char newChar)
// We perform this operation even if there are 0 elements remaining, as it is cheaper than the
// additional check which would introduce a branch here.

i = (nuint)((uint)Length - Vector<ushort>.Count);
i = (uint)(Length - Vector<ushort>.Count);
original = Vector.LoadUnsafe(ref GetRawStringDataAsUInt16(), i);
equals = Vector.Equals(original, oldChars);
results = Vector.ConditionalSelect(equals, newChars, original);
Expand Down