From c090d9059f650fb903061e8633db0f4f3910f67a Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 8 Nov 2018 11:45:13 -0800 Subject: [PATCH] Remove cached invariant globalization mode flag Direct check of readonly flag is better with tiered JITing (the check is optimized out) --- .../System/Globalization/CompareInfo.Unix.cs | 38 +++++++-------- .../System/Globalization/CompareInfo.Windows.cs | 30 ++++++------ .../shared/System/Globalization/CompareInfo.cs | 54 ++++++++++------------ .../shared/System/Globalization/TextInfo.Unix.cs | 2 +- .../System/Globalization/TextInfo.Windows.cs | 4 +- .../shared/System/Globalization/TextInfo.cs | 19 ++++---- 6 files changed, 70 insertions(+), 77 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs index 966cc9d..a55b966 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs @@ -22,7 +22,7 @@ namespace System.Globalization { _sortName = culture.SortName; - if (_invariantMode) + if (GlobalizationMode.Invariant) { _isAsciiEqualityOrdinal = true; } @@ -210,7 +210,7 @@ namespace System.Globalization // that takes two spans. But due to this issue, that's adding significant overhead. private unsafe int CompareString(ReadOnlySpan string1, string string2, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(string2 != null); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); @@ -223,7 +223,7 @@ namespace System.Globalization private unsafe int CompareString(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); fixed (char* pString1 = &MemoryMarshal.GetReference(string1)) @@ -235,7 +235,7 @@ namespace System.Globalization internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(target != null); @@ -286,7 +286,7 @@ namespace System.Globalization // For now, this method is only called from Span APIs with either options == CompareOptions.None or CompareOptions.IgnoreCase internal unsafe int IndexOfCore(ReadOnlySpan source, ReadOnlySpan target, CompareOptions options, int* matchLengthPtr, bool fromBeginning) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(source.Length != 0); Debug.Assert(target.Length != 0); @@ -317,7 +317,7 @@ namespace System.Globalization /// private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan source, ReadOnlySpan target, CompareOptions options, int* matchLengthPtr, bool fromBeginning) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!target.IsEmpty); @@ -403,7 +403,7 @@ namespace System.Globalization private unsafe int IndexOfOrdinalHelper(ReadOnlySpan source, ReadOnlySpan target, CompareOptions options, int* matchLengthPtr, bool fromBeginning) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!target.IsEmpty); @@ -478,7 +478,7 @@ namespace System.Globalization private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(target != null); @@ -516,7 +516,7 @@ namespace System.Globalization private bool StartsWith(string source, string prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(!string.IsNullOrEmpty(prefix)); @@ -534,7 +534,7 @@ namespace System.Globalization private unsafe bool StartsWith(ReadOnlySpan source, ReadOnlySpan prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!prefix.IsEmpty); @@ -568,7 +568,7 @@ namespace System.Globalization private unsafe bool StartsWithOrdinalIgnoreCaseHelper(ReadOnlySpan source, ReadOnlySpan prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!prefix.IsEmpty); @@ -614,7 +614,7 @@ namespace System.Globalization private unsafe bool StartsWithOrdinalHelper(ReadOnlySpan source, ReadOnlySpan prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!prefix.IsEmpty); @@ -649,7 +649,7 @@ namespace System.Globalization private bool EndsWith(string source, string suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(!string.IsNullOrEmpty(suffix)); @@ -667,7 +667,7 @@ namespace System.Globalization private unsafe bool EndsWith(ReadOnlySpan source, ReadOnlySpan suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!suffix.IsEmpty); @@ -701,7 +701,7 @@ namespace System.Globalization private unsafe bool EndsWithOrdinalIgnoreCaseHelper(ReadOnlySpan source, ReadOnlySpan suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!suffix.IsEmpty); @@ -747,7 +747,7 @@ namespace System.Globalization private unsafe bool EndsWithOrdinalHelper(ReadOnlySpan source, ReadOnlySpan suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!suffix.IsEmpty); @@ -782,7 +782,7 @@ namespace System.Globalization private unsafe SortKey CreateSortKey(string source, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); if (source==null) { throw new ArgumentNullException(nameof(source)); } @@ -861,7 +861,7 @@ namespace System.Globalization internal unsafe int GetHashCodeOfStringCore(ReadOnlySpan source, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); if (source.Length == 0) @@ -932,7 +932,7 @@ namespace System.Globalization private SortVersion GetSortVersion() { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); int sortVersion = Interop.Globalization.GetSortVersion(_sortHandle); return new SortVersion(sortVersion, LCID, new Guid(sortVersion, 0, 0, 0, 0, 0, 0, diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs index f6fb690..6aeed0f 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs @@ -16,7 +16,7 @@ namespace System.Globalization { _sortName = culture.SortName; - if (_invariantMode) + if (GlobalizationMode.Invariant) { _sortHandle = IntPtr.Zero; } @@ -114,7 +114,7 @@ namespace System.Globalization private unsafe int GetHashCodeOfStringCore(ReadOnlySpan source, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); if (source.Length == 0) @@ -188,7 +188,7 @@ namespace System.Globalization private unsafe int CompareString(ReadOnlySpan string1, string string2, CompareOptions options) { Debug.Assert(string2 != null); - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); string localeName = _sortHandle != IntPtr.Zero ? null : _sortName; @@ -221,7 +221,7 @@ namespace System.Globalization private unsafe int CompareString(ReadOnlySpan string1, ReadOnlySpan string2, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); string localeName = _sortHandle != IntPtr.Zero ? null : _sortName; @@ -259,7 +259,7 @@ namespace System.Globalization ReadOnlySpan lpStringValue, int* pcchFound) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!lpStringSource.IsEmpty); Debug.Assert(!lpStringValue.IsEmpty); @@ -293,7 +293,7 @@ namespace System.Globalization int cchValue, int* pcchFound) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(lpStringSource != null); Debug.Assert(lpStringValue != null); @@ -322,7 +322,7 @@ namespace System.Globalization internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(source != null); Debug.Assert(target != null); @@ -365,7 +365,7 @@ namespace System.Globalization internal unsafe int IndexOfCore(ReadOnlySpan source, ReadOnlySpan target, CompareOptions options, int* matchLengthPtr, bool fromBeginning) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(source.Length != 0); Debug.Assert(target.Length != 0); @@ -377,7 +377,7 @@ namespace System.Globalization private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(target != null); @@ -406,7 +406,7 @@ namespace System.Globalization private unsafe bool StartsWith(string source, string prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(!string.IsNullOrEmpty(prefix)); @@ -418,7 +418,7 @@ namespace System.Globalization private unsafe bool StartsWith(ReadOnlySpan source, ReadOnlySpan prefix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!prefix.IsEmpty); @@ -429,7 +429,7 @@ namespace System.Globalization private unsafe bool EndsWith(string source, string suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!string.IsNullOrEmpty(source)); Debug.Assert(!string.IsNullOrEmpty(suffix)); @@ -441,7 +441,7 @@ namespace System.Globalization private unsafe bool EndsWith(ReadOnlySpan source, ReadOnlySpan suffix, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!suffix.IsEmpty); @@ -539,7 +539,7 @@ namespace System.Globalization private unsafe SortKey CreateSortKey(string source, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); if (source == null) { throw new ArgumentNullException(nameof(source)); } @@ -636,7 +636,7 @@ namespace System.Globalization private unsafe SortVersion GetSortVersion() { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Interop.Kernel32.NlsVersionInfoEx nlsVersion = new Interop.Kernel32.NlsVersionInfoEx(); nlsVersion.dwNLSVersionInfoSize = sizeof(Interop.Kernel32.NlsVersionInfoEx); diff --git a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs index bfe509d..6cd8c80 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.cs @@ -76,10 +76,6 @@ namespace System.Globalization [OptionalField(VersionAdded = 3)] private SortVersion m_SortVersion; // Do not rename (binary serialization) - // _invariantMode is defined for the perf reason as accessing the instance field is faster than access the static property GlobalizationMode.Invariant - [NonSerialized] - private readonly bool _invariantMode = GlobalizationMode.Invariant; - private int culture; // Do not rename (binary serialization). The fields sole purpose is to support Desktop serialization. internal CompareInfo(CultureInfo culture) @@ -338,7 +334,7 @@ namespace System.Globalization return (1); // non-null > null } - if (_invariantMode) + if (GlobalizationMode.Invariant) { if ((options & CompareOptions.IgnoreCase) != 0) return CompareOrdinalIgnoreCase(string1, string2); @@ -381,7 +377,7 @@ namespace System.Globalization return 1; } - if (_invariantMode) + if (GlobalizationMode.Invariant) { return (options & CompareOptions.IgnoreCase) != 0 ? CompareOrdinalIgnoreCase(string1, string2.AsSpan()) : @@ -397,7 +393,7 @@ namespace System.Globalization if (string1.Length == 0 || string2.Length == 0) return string1.Length - string2.Length; - return _invariantMode ? + return GlobalizationMode.Invariant ? string.CompareOrdinal(string1, string2) : CompareString(string1, string2, CompareOptions.None); } @@ -408,7 +404,7 @@ namespace System.Globalization if (string1.Length == 0 || string2.Length == 0) return string1.Length - string2.Length; - return _invariantMode ? + return GlobalizationMode.Invariant ? CompareOrdinalIgnoreCase(string1, string2) : CompareString(string1, string2, CompareOptions.IgnoreCase); } @@ -509,7 +505,7 @@ namespace System.Globalization return string.CompareOrdinal(span1, span2); } - if (_invariantMode) + if (GlobalizationMode.Invariant) { if ((options & CompareOptions.IgnoreCase) != 0) return CompareOrdinalIgnoreCase(span1, span2); @@ -775,7 +771,7 @@ namespace System.Globalization throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); } - if (_invariantMode) + if (GlobalizationMode.Invariant) { return source.StartsWith(prefix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); } @@ -788,7 +784,7 @@ namespace System.Globalization Debug.Assert(prefix.Length != 0); Debug.Assert(source.Length != 0); Debug.Assert((options & ValidIndexMaskOffFlags) == 0); - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); return StartsWith(source, prefix, options); @@ -840,7 +836,7 @@ namespace System.Globalization throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); } - if (_invariantMode) + if (GlobalizationMode.Invariant) { return source.EndsWith(suffix, (options & CompareOptions.IgnoreCase) != 0 ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal); } @@ -853,7 +849,7 @@ namespace System.Globalization Debug.Assert(suffix.Length != 0); Debug.Assert(source.Length != 0); Debug.Assert((options & ValidIndexMaskOffFlags) == 0); - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0); return EndsWith(source, suffix, options); @@ -986,7 +982,7 @@ namespace System.Globalization if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); - if (_invariantMode) + if (GlobalizationMode.Invariant) return IndexOfOrdinal(source, new string(value, 1), startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); return IndexOfCore(source, new string(value, 1), startIndex, count, options, null); @@ -1034,7 +1030,7 @@ namespace System.Globalization if ((options & ValidIndexMaskOffFlags) != 0 && (options != CompareOptions.Ordinal)) throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options)); - if (_invariantMode) + if (GlobalizationMode.Invariant) return IndexOfOrdinal(source, value, startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); return IndexOfCore(source, value, startIndex, count, options, null); @@ -1042,7 +1038,7 @@ namespace System.Globalization internal int IndexOfOrdinal(ReadOnlySpan source, ReadOnlySpan value, bool ignoreCase) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!value.IsEmpty); return IndexOfOrdinalCore(source, value, ignoreCase, fromBeginning: true); @@ -1050,7 +1046,7 @@ namespace System.Globalization internal int LastIndexOfOrdinal(ReadOnlySpan source, ReadOnlySpan value, bool ignoreCase) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!value.IsEmpty); return IndexOfOrdinalCore(source, value, ignoreCase, fromBeginning: false); @@ -1058,7 +1054,7 @@ namespace System.Globalization internal unsafe int IndexOf(ReadOnlySpan source, ReadOnlySpan value, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!value.IsEmpty); return IndexOfCore(source, value, options, null, fromBeginning: true); @@ -1066,7 +1062,7 @@ namespace System.Globalization internal unsafe int LastIndexOf(ReadOnlySpan source, ReadOnlySpan value, CompareOptions options) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(!source.IsEmpty); Debug.Assert(!value.IsEmpty); return IndexOfCore(source, value, options, null, fromBeginning: false); @@ -1106,7 +1102,7 @@ namespace System.Globalization return res; } - if (_invariantMode) + if (GlobalizationMode.Invariant) { int res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); if (res >= 0) @@ -1121,7 +1117,7 @@ namespace System.Globalization internal int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase) { - if (_invariantMode) + if (GlobalizationMode.Invariant) { return InvariantIndexOf(source, value, startIndex, count, ignoreCase); } @@ -1256,7 +1252,7 @@ namespace System.Globalization return source.LastIndexOf(value.ToString(), startIndex, count, StringComparison.OrdinalIgnoreCase); } - if (_invariantMode) + if (GlobalizationMode.Invariant) return InvariantLastIndexOf(source, new string(value, 1), startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); return LastIndexOfCore(source, value.ToString(), startIndex, count, options); @@ -1307,7 +1303,7 @@ namespace System.Globalization return LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase: true); } - if (_invariantMode) + if (GlobalizationMode.Invariant) return InvariantLastIndexOf(source, value, startIndex, count, (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); return LastIndexOfCore(source, value, startIndex, count, options); @@ -1315,7 +1311,7 @@ namespace System.Globalization internal int LastIndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase) { - if (_invariantMode) + if (GlobalizationMode.Invariant) { return InvariantLastIndexOf(source, value, startIndex, count, ignoreCase); } @@ -1332,7 +1328,7 @@ namespace System.Globalization //////////////////////////////////////////////////////////////////////// public virtual SortKey GetSortKey(string source, CompareOptions options) { - if (_invariantMode) + if (GlobalizationMode.Invariant) return InvariantCreateSortKey(source, options); return CreateSortKey(source, options); @@ -1341,7 +1337,7 @@ namespace System.Globalization public virtual SortKey GetSortKey(string source) { - if (_invariantMode) + if (GlobalizationMode.Invariant) return InvariantCreateSortKey(source, CompareOptions.None); return CreateSortKey(source, CompareOptions.None); @@ -1424,7 +1420,7 @@ namespace System.Globalization { // No unsupported flags are set - continue on with the regular logic - if (_invariantMode) + if (GlobalizationMode.Invariant) { return ((options & CompareOptions.IgnoreCase) != 0) ? source.GetHashCodeOrdinalIgnoreCase() : source.GetHashCode(); } @@ -1463,7 +1459,7 @@ namespace System.Globalization { // No unsupported flags are set - continue on with the regular logic - if (_invariantMode) + if (GlobalizationMode.Invariant) { return ((options & CompareOptions.IgnoreCase) != 0) ? string.GetHashCodeOrdinalIgnoreCase(source) : string.GetHashCode(source); } @@ -1506,7 +1502,7 @@ namespace System.Globalization { if (m_SortVersion == null) { - if (_invariantMode) + if (GlobalizationMode.Invariant) { m_SortVersion = new SortVersion(0, CultureInfo.LOCALE_INVARIANT, new Guid(0, 0, 0, 0, 0, 0, 0, (byte) (CultureInfo.LOCALE_INVARIANT >> 24), diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs index c431e46..45cf55c 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Unix.cs @@ -30,7 +30,7 @@ namespace System.Globalization internal unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); if (IsInvariant) { diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs index 6e5e321..d0c8594 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.Windows.cs @@ -10,7 +10,7 @@ namespace System.Globalization { private unsafe void FinishInitialization() { - if (_invariantMode) + if (GlobalizationMode.Invariant) { _sortHandle = IntPtr.Zero; return; @@ -25,7 +25,7 @@ namespace System.Globalization private unsafe void ChangeCase(char* pSource, int pSourceLen, char* pResult, int pResultLen, bool toUpper) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(pSource != null); Debug.Assert(pResult != null); Debug.Assert(pSourceLen >= 0); diff --git a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs index 8ecda47..680923e 100644 --- a/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Globalization/TextInfo.cs @@ -54,9 +54,6 @@ namespace System.Globalization private Tristate _isAsciiCasingSameAsInvariant = Tristate.NotInitialized; - // _invariantMode is defined for the perf reason as accessing the instance field is faster than access the static property GlobalizationMode.Invariant - private readonly bool _invariantMode = GlobalizationMode.Invariant; - // Invariant text info internal static TextInfo Invariant { @@ -192,7 +189,7 @@ namespace System.Globalization //////////////////////////////////////////////////////////////////////// public virtual char ToLower(char c) { - if (_invariantMode || (IsAscii(c) && IsAsciiCasingSameAsInvariant)) + if (GlobalizationMode.Invariant || (IsAscii(c) && IsAsciiCasingSameAsInvariant)) { return ToLowerAsciiInvariant(c); } @@ -204,7 +201,7 @@ namespace System.Globalization { if (str == null) { throw new ArgumentNullException(nameof(str)); } - if (_invariantMode) + if (GlobalizationMode.Invariant) { return ToLowerAsciiInvariant(str); } @@ -214,7 +211,7 @@ namespace System.Globalization private unsafe char ChangeCase(char c, bool toUpper) { - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); char dst = default; ChangeCase(&c, 1, &dst, 1, toUpper); @@ -247,7 +244,7 @@ namespace System.Globalization Debug.Assert(typeof(TConversion) == typeof(ToUpperConversion) || typeof(TConversion) == typeof(ToLowerConversion)); bool toUpper = typeof(TConversion) == typeof(ToUpperConversion); // JIT will treat this as a constant in release builds - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(charCount >= 0); if (charCount == 0) @@ -354,7 +351,7 @@ namespace System.Globalization Debug.Assert(typeof(TConversion) == typeof(ToUpperConversion) || typeof(TConversion) == typeof(ToLowerConversion)); bool toUpper = typeof(TConversion) == typeof(ToUpperConversion); // JIT will treat this as a constant in release builds - Debug.Assert(!_invariantMode); + Debug.Assert(!GlobalizationMode.Invariant); Debug.Assert(source != null); // If the string is empty, we're done. @@ -585,7 +582,7 @@ namespace System.Globalization //////////////////////////////////////////////////////////////////////// public virtual char ToUpper(char c) { - if (_invariantMode || (IsAscii(c) && IsAsciiCasingSameAsInvariant)) + if (GlobalizationMode.Invariant || (IsAscii(c) && IsAsciiCasingSameAsInvariant)) { return ToUpperAsciiInvariant(c); } @@ -597,7 +594,7 @@ namespace System.Globalization { if (str == null) { throw new ArgumentNullException(nameof(str)); } - if (_invariantMode) + if (GlobalizationMode.Invariant) { return ToUpperAsciiInvariant(str); } @@ -856,7 +853,7 @@ namespace System.Globalization { // for surrogate pairs do a ToUpper operation on the substring ReadOnlySpan src = input.AsSpan(inputIndex, 2); - if (_invariantMode) + if (GlobalizationMode.Invariant) { result.Append(src); // surrogate pair in invariant mode, so changing case is a nop } -- 2.7.4