Fix DateTimeFormat.FormatCustomized optimization bug
authorstephentoub <stoub@microsoft.com>
Thu, 28 Jan 2016 04:33:02 +0000 (20:33 -0800)
committerstephentoub <stoub@microsoft.com>
Thu, 28 Jan 2016 04:35:26 +0000 (20:35 -0800)
After reverting https://github.com/dotnet/coreclr/pull/2617, which resulted in backslash escapes being included incorrectly, replaces it with a simpler fix that avoids the same allocations and copies by simply passing in the overarching StringBuilder.  The call sites throw away the StringBuilder if an exception occurs, so we can simply write to it directly rather than first writing to a temporary and then dumping that temporary into the overarching result.

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

index adc6d52d1501e106427d3d538e31123419ce0a18..cdb7032a868abffeb4842586a7d4d62b9d3288e9 100644 (file)
@@ -288,7 +288,7 @@ namespace System {
     
         //
         // The pos should point to a quote character. This method will
-        // get the string encloed by the quote character.
+        // append to the result StringBuilder the string encloed by the quote character.
         //
         internal static int ParseQuoteString(String format, int pos, StringBuilder result)
         {
@@ -630,9 +630,7 @@ namespace System {
                         break;
                     case '\'':
                     case '\"':
-                        StringBuilder enquotedString = new StringBuilder();
-                        tokenLen = ParseQuoteString(format, i, enquotedString); 
-                        result.Append(enquotedString);
+                        tokenLen = ParseQuoteString(format, i, result); 
                         break;
                     case '%':
                         // Optional format character.
index 4a9ccfda14cd8ddbcac67c5977e621c238ca0d3e..8f58623868757a92cc85647450b2002eef6795d5 100644 (file)
@@ -232,9 +232,7 @@ namespace System.Globalization {
                         break;
                     case '\'':
                     case '\"':
-                        StringBuilder enquotedString = new StringBuilder();
-                        tokenLen = DateTimeFormat.ParseQuoteString(format, i, enquotedString); 
-                        result.Append(enquotedString);
+                        tokenLen = DateTimeFormat.ParseQuoteString(format, i, result); 
                         break;
                     case '%':
                         // Optional format character.