From 065ca1cbb25154db8c5f80dace8140f1abc199ec Mon Sep 17 00:00:00 2001 From: stephentoub Date: Wed, 27 Jan 2016 20:33:02 -0800 Subject: [PATCH] Fix DateTimeFormat.FormatCustomized optimization bug 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 | 6 ++---- src/mscorlib/src/System/Globalization/TimeSpanFormat.cs | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/mscorlib/src/System/Globalization/DateTimeFormat.cs b/src/mscorlib/src/System/Globalization/DateTimeFormat.cs index adc6d52d15..cdb7032a86 100644 --- a/src/mscorlib/src/System/Globalization/DateTimeFormat.cs +++ b/src/mscorlib/src/System/Globalization/DateTimeFormat.cs @@ -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. diff --git a/src/mscorlib/src/System/Globalization/TimeSpanFormat.cs b/src/mscorlib/src/System/Globalization/TimeSpanFormat.cs index 4a9ccfda14..8f58623868 100644 --- a/src/mscorlib/src/System/Globalization/TimeSpanFormat.cs +++ b/src/mscorlib/src/System/Globalization/TimeSpanFormat.cs @@ -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. -- 2.34.1