Replace custom AnsiToLower with more efficient ToLowerAsciiInvariant (dotnet/coreclr...
authorStephen Toub <stoub@microsoft.com>
Tue, 20 Nov 2018 19:58:47 +0000 (14:58 -0500)
committerGitHub <noreply@github.com>
Tue, 20 Nov 2018 19:58:47 +0000 (14:58 -0500)
Avoids all of the StringBuilder-related costs.

Commit migrated from https://github.com/dotnet/coreclr/commit/e5ff28022e99b391ca75867c1a378beee0e594f2

src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
src/libraries/System.Private.CoreLib/src/System/Globalization/TextInfo.cs

index cb6a810..c747f98 100644 (file)
@@ -2407,35 +2407,8 @@ namespace System.Globalization
 
         // Helper
         // This is ONLY used for caching names and shouldn't be used for anything else
-        internal static string AnsiToLower(string testString)
-        {
-            int index = 0;
-
-            while (index<testString.Length && (testString[index]<'A' || testString[index]>'Z' ))
-            {
-                index++;
-            }
-            if (index >= testString.Length)
-            {
-                return testString; // we didn't really change the string
-            }
-
-            StringBuilder sb = new StringBuilder(testString.Length);
-            for (int i=0; i<index; i++)
-            {
-                sb.Append(testString[i]);
-            }
-
-            sb.Append((char) (testString[index] -'A' + 'a'));
-
-            for (int ich = index+1; ich < testString.Length; ich++)
-            {
-                char ch = testString[ich];
-                sb.Append(ch <= 'Z' && ch >= 'A' ? (char)(ch - 'A' + 'a') : ch);
-            }
-
-            return (sb.ToString());
-        }
+        internal static string AnsiToLower(string testString) =>
+            TextInfo.ToLowerAsciiInvariant(testString);
 
         /// <remarks>
         /// The numeric values of the enum members match their Win32 counterparts.  The CultureData Win32 PAL implementation
index 680923e..61e2160 100644 (file)
@@ -451,7 +451,7 @@ namespace System.Globalization
             }
         }
 
-        private static unsafe string ToLowerAsciiInvariant(string s)
+        internal static unsafe string ToLowerAsciiInvariant(string s)
         {
             if (s.Length == 0)
             {