Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit c090d90

Browse files
committed
Remove cached invariant globalization mode flag
Direct check of readonly flag is better with tiered JITing (the check is optimized out)
1 parent c2f0fba commit c090d90

File tree

6 files changed

+70
-77
lines changed

6 files changed

+70
-77
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private void InitSort(CultureInfo culture)
2222
{
2323
_sortName = culture.SortName;
2424

25-
if (_invariantMode)
25+
if (GlobalizationMode.Invariant)
2626
{
2727
_isAsciiEqualityOrdinal = true;
2828
}
@@ -210,7 +210,7 @@ private static unsafe int CompareStringOrdinalIgnoreCase(ref char string1, int c
210210
// that takes two spans. But due to this issue, that's adding significant overhead.
211211
private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, CompareOptions options)
212212
{
213-
Debug.Assert(!_invariantMode);
213+
Debug.Assert(!GlobalizationMode.Invariant);
214214
Debug.Assert(string2 != null);
215215
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
216216

@@ -223,7 +223,7 @@ private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, Com
223223

224224
private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options)
225225
{
226-
Debug.Assert(!_invariantMode);
226+
Debug.Assert(!GlobalizationMode.Invariant);
227227
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
228228

229229
fixed (char* pString1 = &MemoryMarshal.GetReference(string1))
@@ -235,7 +235,7 @@ private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char>
235235

236236
internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr)
237237
{
238-
Debug.Assert(!_invariantMode);
238+
Debug.Assert(!GlobalizationMode.Invariant);
239239

240240
Debug.Assert(!string.IsNullOrEmpty(source));
241241
Debug.Assert(target != null);
@@ -286,7 +286,7 @@ internal unsafe int IndexOfCore(string source, string target, int startIndex, in
286286
// For now, this method is only called from Span APIs with either options == CompareOptions.None or CompareOptions.IgnoreCase
287287
internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
288288
{
289-
Debug.Assert(!_invariantMode);
289+
Debug.Assert(!GlobalizationMode.Invariant);
290290
Debug.Assert(source.Length != 0);
291291
Debug.Assert(target.Length != 0);
292292

@@ -317,7 +317,7 @@ internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> ta
317317
/// <returns></returns>
318318
private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
319319
{
320-
Debug.Assert(!_invariantMode);
320+
Debug.Assert(!GlobalizationMode.Invariant);
321321

322322
Debug.Assert(!source.IsEmpty);
323323
Debug.Assert(!target.IsEmpty);
@@ -403,7 +403,7 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
403403

404404
private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
405405
{
406-
Debug.Assert(!_invariantMode);
406+
Debug.Assert(!GlobalizationMode.Invariant);
407407

408408
Debug.Assert(!source.IsEmpty);
409409
Debug.Assert(!target.IsEmpty);
@@ -478,7 +478,7 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
478478

479479
private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
480480
{
481-
Debug.Assert(!_invariantMode);
481+
Debug.Assert(!GlobalizationMode.Invariant);
482482

483483
Debug.Assert(!string.IsNullOrEmpty(source));
484484
Debug.Assert(target != null);
@@ -516,7 +516,7 @@ private unsafe int LastIndexOfCore(string source, string target, int startIndex,
516516

517517
private bool StartsWith(string source, string prefix, CompareOptions options)
518518
{
519-
Debug.Assert(!_invariantMode);
519+
Debug.Assert(!GlobalizationMode.Invariant);
520520

521521
Debug.Assert(!string.IsNullOrEmpty(source));
522522
Debug.Assert(!string.IsNullOrEmpty(prefix));
@@ -534,7 +534,7 @@ private bool StartsWith(string source, string prefix, CompareOptions options)
534534

535535
private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
536536
{
537-
Debug.Assert(!_invariantMode);
537+
Debug.Assert(!GlobalizationMode.Invariant);
538538

539539
Debug.Assert(!source.IsEmpty);
540540
Debug.Assert(!prefix.IsEmpty);
@@ -568,7 +568,7 @@ private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> pre
568568

569569
private unsafe bool StartsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
570570
{
571-
Debug.Assert(!_invariantMode);
571+
Debug.Assert(!GlobalizationMode.Invariant);
572572

573573
Debug.Assert(!source.IsEmpty);
574574
Debug.Assert(!prefix.IsEmpty);
@@ -614,7 +614,7 @@ private unsafe bool StartsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source,
614614

615615
private unsafe bool StartsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
616616
{
617-
Debug.Assert(!_invariantMode);
617+
Debug.Assert(!GlobalizationMode.Invariant);
618618

619619
Debug.Assert(!source.IsEmpty);
620620
Debug.Assert(!prefix.IsEmpty);
@@ -649,7 +649,7 @@ private unsafe bool StartsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlyS
649649

650650
private bool EndsWith(string source, string suffix, CompareOptions options)
651651
{
652-
Debug.Assert(!_invariantMode);
652+
Debug.Assert(!GlobalizationMode.Invariant);
653653

654654
Debug.Assert(!string.IsNullOrEmpty(source));
655655
Debug.Assert(!string.IsNullOrEmpty(suffix));
@@ -667,7 +667,7 @@ private bool EndsWith(string source, string suffix, CompareOptions options)
667667

668668
private unsafe bool EndsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
669669
{
670-
Debug.Assert(!_invariantMode);
670+
Debug.Assert(!GlobalizationMode.Invariant);
671671

672672
Debug.Assert(!source.IsEmpty);
673673
Debug.Assert(!suffix.IsEmpty);
@@ -701,7 +701,7 @@ private unsafe bool EndsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> suffi
701701

702702
private unsafe bool EndsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
703703
{
704-
Debug.Assert(!_invariantMode);
704+
Debug.Assert(!GlobalizationMode.Invariant);
705705

706706
Debug.Assert(!source.IsEmpty);
707707
Debug.Assert(!suffix.IsEmpty);
@@ -747,7 +747,7 @@ private unsafe bool EndsWithOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, R
747747

748748
private unsafe bool EndsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
749749
{
750-
Debug.Assert(!_invariantMode);
750+
Debug.Assert(!GlobalizationMode.Invariant);
751751

752752
Debug.Assert(!source.IsEmpty);
753753
Debug.Assert(!suffix.IsEmpty);
@@ -782,7 +782,7 @@ private unsafe bool EndsWithOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpa
782782

783783
private unsafe SortKey CreateSortKey(string source, CompareOptions options)
784784
{
785-
Debug.Assert(!_invariantMode);
785+
Debug.Assert(!GlobalizationMode.Invariant);
786786

787787
if (source==null) { throw new ArgumentNullException(nameof(source)); }
788788

@@ -861,7 +861,7 @@ private static unsafe bool IsSortable(char *text, int length)
861861

862862
internal unsafe int GetHashCodeOfStringCore(ReadOnlySpan<char> source, CompareOptions options)
863863
{
864-
Debug.Assert(!_invariantMode);
864+
Debug.Assert(!GlobalizationMode.Invariant);
865865
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
866866

867867
if (source.Length == 0)
@@ -932,7 +932,7 @@ private static byte[] GetNullTerminatedUtf8String(string s)
932932

933933
private SortVersion GetSortVersion()
934934
{
935-
Debug.Assert(!_invariantMode);
935+
Debug.Assert(!GlobalizationMode.Invariant);
936936

937937
int sortVersion = Interop.Globalization.GetSortVersion(_sortHandle);
938938
return new SortVersion(sortVersion, LCID, new Guid(sortVersion, 0, 0, 0, 0, 0, 0,

src/System.Private.CoreLib/shared/System/Globalization/CompareInfo.Windows.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private unsafe void InitSort(CultureInfo culture)
1616
{
1717
_sortName = culture.SortName;
1818

19-
if (_invariantMode)
19+
if (GlobalizationMode.Invariant)
2020
{
2121
_sortHandle = IntPtr.Zero;
2222
}
@@ -114,7 +114,7 @@ internal static int LastIndexOfOrdinalCore(string source, string value, int star
114114

115115
private unsafe int GetHashCodeOfStringCore(ReadOnlySpan<char> source, CompareOptions options)
116116
{
117-
Debug.Assert(!_invariantMode);
117+
Debug.Assert(!GlobalizationMode.Invariant);
118118
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
119119

120120
if (source.Length == 0)
@@ -188,7 +188,7 @@ private static unsafe int CompareStringOrdinalIgnoreCase(ref char string1, int c
188188
private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, CompareOptions options)
189189
{
190190
Debug.Assert(string2 != null);
191-
Debug.Assert(!_invariantMode);
191+
Debug.Assert(!GlobalizationMode.Invariant);
192192
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
193193

194194
string localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
@@ -221,7 +221,7 @@ private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, Com
221221

222222
private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> string2, CompareOptions options)
223223
{
224-
Debug.Assert(!_invariantMode);
224+
Debug.Assert(!GlobalizationMode.Invariant);
225225
Debug.Assert((options & (CompareOptions.Ordinal | CompareOptions.OrdinalIgnoreCase)) == 0);
226226

227227
string localeName = _sortHandle != IntPtr.Zero ? null : _sortName;
@@ -259,7 +259,7 @@ private unsafe int FindString(
259259
ReadOnlySpan<char> lpStringValue,
260260
int* pcchFound)
261261
{
262-
Debug.Assert(!_invariantMode);
262+
Debug.Assert(!GlobalizationMode.Invariant);
263263
Debug.Assert(!lpStringSource.IsEmpty);
264264
Debug.Assert(!lpStringValue.IsEmpty);
265265

@@ -293,7 +293,7 @@ private unsafe int FindString(
293293
int cchValue,
294294
int* pcchFound)
295295
{
296-
Debug.Assert(!_invariantMode);
296+
Debug.Assert(!GlobalizationMode.Invariant);
297297
Debug.Assert(lpStringSource != null);
298298
Debug.Assert(lpStringValue != null);
299299

@@ -322,7 +322,7 @@ private unsafe int FindString(
322322

323323
internal unsafe int IndexOfCore(string source, string target, int startIndex, int count, CompareOptions options, int* matchLengthPtr)
324324
{
325-
Debug.Assert(!_invariantMode);
325+
Debug.Assert(!GlobalizationMode.Invariant);
326326

327327
Debug.Assert(source != null);
328328
Debug.Assert(target != null);
@@ -365,7 +365,7 @@ internal unsafe int IndexOfCore(string source, string target, int startIndex, in
365365

366366
internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
367367
{
368-
Debug.Assert(!_invariantMode);
368+
Debug.Assert(!GlobalizationMode.Invariant);
369369

370370
Debug.Assert(source.Length != 0);
371371
Debug.Assert(target.Length != 0);
@@ -377,7 +377,7 @@ internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> ta
377377

378378
private unsafe int LastIndexOfCore(string source, string target, int startIndex, int count, CompareOptions options)
379379
{
380-
Debug.Assert(!_invariantMode);
380+
Debug.Assert(!GlobalizationMode.Invariant);
381381

382382
Debug.Assert(!string.IsNullOrEmpty(source));
383383
Debug.Assert(target != null);
@@ -406,7 +406,7 @@ private unsafe int LastIndexOfCore(string source, string target, int startIndex,
406406

407407
private unsafe bool StartsWith(string source, string prefix, CompareOptions options)
408408
{
409-
Debug.Assert(!_invariantMode);
409+
Debug.Assert(!GlobalizationMode.Invariant);
410410

411411
Debug.Assert(!string.IsNullOrEmpty(source));
412412
Debug.Assert(!string.IsNullOrEmpty(prefix));
@@ -418,7 +418,7 @@ private unsafe bool StartsWith(string source, string prefix, CompareOptions opti
418418

419419
private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> prefix, CompareOptions options)
420420
{
421-
Debug.Assert(!_invariantMode);
421+
Debug.Assert(!GlobalizationMode.Invariant);
422422

423423
Debug.Assert(!source.IsEmpty);
424424
Debug.Assert(!prefix.IsEmpty);
@@ -429,7 +429,7 @@ private unsafe bool StartsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> pre
429429

430430
private unsafe bool EndsWith(string source, string suffix, CompareOptions options)
431431
{
432-
Debug.Assert(!_invariantMode);
432+
Debug.Assert(!GlobalizationMode.Invariant);
433433

434434
Debug.Assert(!string.IsNullOrEmpty(source));
435435
Debug.Assert(!string.IsNullOrEmpty(suffix));
@@ -441,7 +441,7 @@ private unsafe bool EndsWith(string source, string suffix, CompareOptions option
441441

442442
private unsafe bool EndsWith(ReadOnlySpan<char> source, ReadOnlySpan<char> suffix, CompareOptions options)
443443
{
444-
Debug.Assert(!_invariantMode);
444+
Debug.Assert(!GlobalizationMode.Invariant);
445445

446446
Debug.Assert(!source.IsEmpty);
447447
Debug.Assert(!suffix.IsEmpty);
@@ -539,7 +539,7 @@ private static unsafe int FastIndexOfString(string source, string target, int st
539539

540540
private unsafe SortKey CreateSortKey(string source, CompareOptions options)
541541
{
542-
Debug.Assert(!_invariantMode);
542+
Debug.Assert(!GlobalizationMode.Invariant);
543543

544544
if (source == null) { throw new ArgumentNullException(nameof(source)); }
545545

@@ -636,7 +636,7 @@ private static int GetNativeCompareFlags(CompareOptions options)
636636

637637
private unsafe SortVersion GetSortVersion()
638638
{
639-
Debug.Assert(!_invariantMode);
639+
Debug.Assert(!GlobalizationMode.Invariant);
640640

641641
Interop.Kernel32.NlsVersionInfoEx nlsVersion = new Interop.Kernel32.NlsVersionInfoEx();
642642
nlsVersion.dwNLSVersionInfoSize = sizeof(Interop.Kernel32.NlsVersionInfoEx);

0 commit comments

Comments
 (0)