From bc766529c0eae0d51d3740dc43a49caa0c213d31 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 4 May 2023 13:22:49 -0700 Subject: [PATCH] Avoid using two-char search in IndexOfOrdinalIgnoreCase for 1-char values (#85781) --- .../System.Private.CoreLib/src/System/Globalization/Ordinal.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs index 6a89be1..d4a5ae7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/Ordinal.cs @@ -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.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.Count) { valueCharU = Unsafe.Add(ref valueRef, valueTailLength); if (char.IsAscii(valueCharU)) -- 2.7.4