Avoid StringBuilder allocation in ResourceManager (#13732)
authorJustin Van Patten <jvp@justinvp.com>
Fri, 1 Sep 2017 14:12:30 +0000 (07:12 -0700)
committerJan Kotas <jkotas@microsoft.com>
Fri, 1 Sep 2017 14:12:30 +0000 (07:12 -0700)
src/mscorlib/src/System/Resources/ResourceManager.cs

index 30222b4aae8acf066b2e05c96373f95c8ae37681..7c565adbbb76ac18eb7f91eb46aeefcddeff3d10 100644 (file)
@@ -525,17 +525,16 @@ namespace System.Resources
         // such as ".ResX", or a completely different format for naming files.
         protected virtual String GetResourceFileName(CultureInfo culture)
         {
-            StringBuilder sb = new StringBuilder(255);
-            sb.Append(BaseNameField);
-            // If this is the neutral culture, don't append culture name.
-            if (!culture.HasInvariantCultureName)
+            // If this is the neutral culture, don't include the culture name.
+            if (culture.HasInvariantCultureName)
             {
-                CultureInfo.VerifyCultureName(culture.Name, true);
-                sb.Append('.');
-                sb.Append(culture.Name);
+                return BaseNameField + ResFileExtension;
+            }
+            else
+            {
+                CultureInfo.VerifyCultureName(culture.Name, throwException: true);
+                return BaseNameField + "." + culture.Name + ResFileExtension;
             }
-            sb.Append(ResFileExtension);
-            return sb.ToString();
         }
 
         // WARNING: This function must be kept in sync with ResourceFallbackManager.GetEnumerator()