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

Globalization mode.invariant #20885

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void InitSort(CultureInfo culture)
{
_sortName = culture.SortName;

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

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

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

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

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);
Expand Down Expand Up @@ -286,7 +286,7 @@ internal unsafe int IndexOfCore(string source, string target, int startIndex, in
// For now, this method is only called from Span APIs with either options == CompareOptions.None or CompareOptions.IgnoreCase
internal unsafe int IndexOfCore(ReadOnlySpan<char> source, ReadOnlySpan<char> target, CompareOptions options, int* matchLengthPtr, bool fromBeginning)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(source.Length != 0);
Debug.Assert(target.Length != 0);

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

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

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

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

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);
Expand Down Expand Up @@ -516,7 +516,7 @@ private unsafe int LastIndexOfCore(string source, string target, int startIndex,

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));
Expand All @@ -534,7 +534,7 @@ private bool StartsWith(string source, string prefix, CompareOptions options)

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

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

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

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

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

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

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));
Expand All @@ -667,7 +667,7 @@ private bool EndsWith(string source, string suffix, CompareOptions options)

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

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

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

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

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

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

private unsafe SortKey CreateSortKey(string source, CompareOptions options)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);

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

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

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

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

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private unsafe void InitSort(CultureInfo culture)
{
_sortName = culture.SortName;

if (_invariantMode)
if (GlobalizationMode.Invariant)
{
_sortHandle = IntPtr.Zero;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ internal static int LastIndexOfOrdinalCore(string source, string value, int star

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

if (source.Length == 0)
Expand Down Expand Up @@ -188,7 +188,7 @@ private static unsafe int CompareStringOrdinalIgnoreCase(ref char string1, int c
private unsafe int CompareString(ReadOnlySpan<char> 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;
Expand Down Expand Up @@ -221,7 +221,7 @@ private unsafe int CompareString(ReadOnlySpan<char> string1, string string2, Com

private unsafe int CompareString(ReadOnlySpan<char> string1, ReadOnlySpan<char> 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;
Expand Down Expand Up @@ -259,7 +259,7 @@ private unsafe int FindString(
ReadOnlySpan<char> lpStringValue,
int* pcchFound)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(!lpStringSource.IsEmpty);
Debug.Assert(!lpStringValue.IsEmpty);

Expand Down Expand Up @@ -293,7 +293,7 @@ private unsafe int FindString(
int cchValue,
int* pcchFound)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);
Debug.Assert(lpStringSource != null);
Debug.Assert(lpStringValue != null);

Expand Down Expand Up @@ -322,7 +322,7 @@ private unsafe int FindString(

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);
Expand Down Expand Up @@ -365,7 +365,7 @@ internal unsafe int IndexOfCore(string source, string target, int startIndex, in

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

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

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);
Expand Down Expand Up @@ -406,7 +406,7 @@ private unsafe int LastIndexOfCore(string source, string target, int startIndex,

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));
Expand All @@ -418,7 +418,7 @@ private unsafe bool StartsWith(string source, string prefix, CompareOptions opti

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

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

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));
Expand All @@ -441,7 +441,7 @@ private unsafe bool EndsWith(string source, string suffix, CompareOptions option

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

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

private unsafe SortKey CreateSortKey(string source, CompareOptions options)
{
Debug.Assert(!_invariantMode);
Debug.Assert(!GlobalizationMode.Invariant);

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

Expand Down Expand Up @@ -636,7 +636,7 @@ private static int GetNativeCompareFlags(CompareOptions options)

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);
Expand Down
Loading