From: Stephen Toub Date: Fri, 8 Sep 2017 14:05:22 +0000 (-0400) Subject: Avoid slicing/extra method call while tokenizing in common case X-Git-Tag: accepted/tizen/base/20180629.140029~958^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=89a825e4a74445bdf29b9114a209ed45f16ddc79;p=platform%2Fupstream%2Fcoreclr.git Avoid slicing/extra method call while tokenizing in common case --- diff --git a/src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs b/src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs index e27333a..4a8059f 100644 --- a/src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs +++ b/src/mscorlib/shared/System/Globalization/DateTimeFormatInfo.cs @@ -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 string1, ReadOnlySpan 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