Avoid slicing/extra method call while tokenizing in common case
authorStephen Toub <stoub@microsoft.com>
Fri, 8 Sep 2017 14:05:22 +0000 (10:05 -0400)
committerStephen Toub <stoub@microsoft.com>
Fri, 6 Oct 2017 12:27:41 +0000 (08:27 -0400)
src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs

index e27333a..4a8059f 100644 (file)
@@ -2813,7 +2813,10 @@ namespace System.Globalization
                             compareStrings = !(Char.IsLetter(nextCh));
                         }
                     }
-                    if (compareStrings && CompareStringIgnoreCaseOptimized(str.Value.Slice(str.Index, value.tokenString.Length), value.tokenString.AsReadOnlySpan()))
+                    
+                    if (compareStrings &&
+                        ((value.tokenString.Length == 1 && str.Value[str.Index] == value.tokenString[0]) ||
+                         Culture.CompareInfo.Compare(str.Value.Slice(str.Index, value.tokenString.Length), value.tokenString.AsReadOnlySpan(), CompareOptions.IgnoreCase) == 0))
                     {
                         tokenType = value.tokenType & TokenMask;
                         tokenValue = value.tokenValue;
@@ -2974,17 +2977,6 @@ namespace System.Globalization
             return (this.Culture.CompareInfo.Compare(string1, offset1, length1, string2, offset2, length2, CompareOptions.IgnoreCase) == 0);
         }
 
-        private bool CompareStringIgnoreCaseOptimized(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2)
-        {
-            // Optimize for one character cases which are common due to date and time separators (/ and :)
-            if (string1.Length == 1 && string2.Length == 1 && string1[0] == string2[0])
-            {
-                return true;
-            }
-
-            return (this.Culture.CompareInfo.Compare(string1, string2, CompareOptions.IgnoreCase) == 0);
-        }
-
         // class DateTimeFormatInfo
 
         internal class TokenHashValue