DateTimeFormat: Avoid intermediate char[] allocation (#6863)
authorJustin Van Patten <jvp@justinvp.com>
Wed, 24 Aug 2016 03:16:22 +0000 (20:16 -0700)
committerJan Kotas <jkotas@microsoft.com>
Wed, 24 Aug 2016 03:16:22 +0000 (20:16 -0700)
An unnecessary intermediate char[] allocation can be avoided by calling
`new string(c, 1)` instead of `new string(new char[] { c })`.

src/mscorlib/src/System/Globalization/DateTimeFormat.cs

index cbb4039a0c56ea1a71131d85d5a6e697451f2956..228e5f56a2056c6e327258a1245a1264e93784e0 100644 (file)
@@ -1009,7 +1009,7 @@ namespace System {
                 case 'O':
                 case 's':
                 case 'u':            
-                    results = new String[] {Format(dateTime, new String(new char[] {format}), dtfi)};
+                    results = new String[] {Format(dateTime, new String(format, 1), dtfi)};
                     break;   
                 default:
                     throw new FormatException(Environment.GetResourceString("Format_InvalidString"));