allow ASCII equality ordinal fast path for en-* cultures (dotnet/coreclr#26905)
authorAdam Sitnik <adam.sitnik@gmail.com>
Tue, 1 Oct 2019 01:25:29 +0000 (03:25 +0200)
committerGitHub <noreply@github.com>
Tue, 1 Oct 2019 01:25:29 +0000 (03:25 +0200)
* allow ASCII equality ordinal fast path for en-* cultures

* dont use StartsWith in the initialization execution path

* Update src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Unix.cs

Co-Authored-By: Jan Kotas <jkotas@microsoft.com>
Commit migrated from https://github.com/dotnet/coreclr/commit/87e4971a68114987d81a21ba6df9035e30255c51

src/libraries/System.Private.CoreLib/src/System/Globalization/CompareInfo.Unix.cs

index 3388c09..4e42a54 100644 (file)
@@ -32,7 +32,12 @@ namespace System.Globalization
             }
             else
             {
-                _isAsciiEqualityOrdinal = (_sortName == "en-US" || _sortName == "");
+                // Inline the following condition to avoid potential implementation cycles within globalization
+                //
+                // _isAsciiEqualityOrdinal = _sortName == "" || _sortName == "en" || _sortName.StartsWith("en-", StringComparison.Ordinal);
+                //
+                _isAsciiEqualityOrdinal = _sortName.Length == 0 ||
+                    (_sortName.Length >= 2 && _sortName[0] == 'e' && _sortName[1] == 'n' && (_sortName.Length == 2 || _sortName[2] == '-'));
 
                 _sortHandle = SortHandleCache.GetCachedSortHandle(_sortName);
             }