Avoid using two-char search in IndexOfOrdinalIgnoreCase for 1-char values (#85781)
authorStephen Toub <stoub@microsoft.com>
Thu, 4 May 2023 20:22:49 +0000 (13:22 -0700)
committerGitHub <noreply@github.com>
Thu, 4 May 2023 20:22:49 +0000 (16:22 -0400)
src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs

index 6a89be1..d4a5ae7 100644 (file)
@@ -327,9 +327,11 @@ namespace System.Globalization
             nint offset = 0;
             bool isLetter = false;
 
-            // If the input is long enough and the value ends with ASCII, we can take a special vectorized
-            // path that compares both the beginning and the end at the same time.
-            if (Vector128.IsHardwareAccelerated && searchSpaceMinusValueTailLength >= Vector128<ushort>.Count)
+            // If the input is long enough and the value ends with ASCII and is at least two characters,
+            // we can take a special vectorized path that compares both the beginning and the end at the same time.
+            if (Vector128.IsHardwareAccelerated &&
+                valueTailLength != 0 &&
+                searchSpaceMinusValueTailLength >= Vector128<ushort>.Count)
             {
                 valueCharU = Unsafe.Add(ref valueRef, valueTailLength);
                 if (char.IsAscii(valueCharU))