Add ASCII optimization to string.ToLower/ToUpper on Unix
authorstephentoub <stoub@microsoft.com>
Mon, 12 Oct 2015 19:06:25 +0000 (15:06 -0400)
committerstephentoub <stoub@microsoft.com>
Wed, 14 Oct 2015 15:14:39 +0000 (11:14 -0400)
Commit migrated from https://github.com/dotnet/coreclr/commit/f48b5ad56a6f6f584cb202c05f5b06c09b7adfbf

src/coreclr/src/mscorlib/corefx/System/Globalization/TextInfo.Unix.cs

index 0d7003f..c16f46b 100644 (file)
@@ -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;