From: stephentoub Date: Mon, 12 Oct 2015 19:06:25 +0000 (-0400) Subject: Add ASCII optimization to string.ToLower/ToUpper on Unix X-Git-Tag: submit/tizen/20210909.063632~11030^2~12130^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=adccaa2c3b1d320a0c47df4c5481fd9dbff266ac;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Add ASCII optimization to string.ToLower/ToUpper on Unix Commit migrated from https://github.com/dotnet/coreclr/commit/f48b5ad56a6f6f584cb202c05f5b06c09b7adfbf --- diff --git a/src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs b/src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs index 0d7003f..c16f46b 100644 --- a/src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs +++ b/src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs @@ -36,9 +36,35 @@ namespace System.Globalization } string result = string.FastAllocateString(s.Length); - fixed (char* pBuf = result) + + fixed (char* pResult = result) { - Interop.GlobalizationInterop.ChangeCase(s, s.Length, pBuf, result.Length, toUpper, m_needsTurkishCasing); + if (IsAsciiCasingSameAsInvariant && s.IsAscii()) + { + fixed (char* pSource = s) + { + int length = s.Length; + char* a = pSource, b = pResult; + if (toUpper) + { + while (length-- != 0) + { + *b++ = ToUpperAsciiInvariant(*a++); + } + } + else + { + while (length-- != 0) + { + *b++ = ToLowerAsciiInvariant(*a++); + } + } + } + } + else + { + Interop.GlobalizationInterop.ChangeCase(s, s.Length, pResult, result.Length, toUpper, m_needsTurkishCasing); + } } return result;