summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStephen Toub <stoub@microsoft.com>2017-09-08 10:25:01 -0400
committerStephen Toub <stoub@microsoft.com>2017-10-06 08:27:42 -0400
commit78ae3ab5ed9e198599a4577aa6ae73f053ac1c02 (patch)
treefe720e0236bd1f2124b41a158ab6b8f3c8850b7e /src
parent63829851715ecf694bbdb07bc5677d6df83a4b15 (diff)
downloadcoreclr-78ae3ab5ed9e198599a4577aa6ae73f053ac1c02.tar.gz
coreclr-78ae3ab5ed9e198599a4577aa6ae73f053ac1c02.tar.bz2
coreclr-78ae3ab5ed9e198599a4577aa6ae73f053ac1c02.zip
Remove StringBuilder allocations from roundtrip format DateTime parsing
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/shared/System/Globalization/DateTimeParse.cs5
-rw-r--r--src/mscorlib/shared/System/Globalization/TimeSpanParse.cs5
2 files changed, 7 insertions, 3 deletions
diff --git a/src/mscorlib/shared/System/Globalization/DateTimeParse.cs b/src/mscorlib/shared/System/Globalization/DateTimeParse.cs
index cad9ae8421..0a1cf9eb34 100644
--- a/src/mscorlib/shared/System/Globalization/DateTimeParse.cs
+++ b/src/mscorlib/shared/System/Globalization/DateTimeParse.cs
@@ -4201,11 +4201,12 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
break;
case '\"':
case '\'':
- StringBuilder enquotedString = new StringBuilder();
+ StringBuilder enquotedString = StringBuilderCache.Acquire();
// Use ParseQuoteString so that we can handle escape characters within the quoted string.
if (!TryParseQuoteString(format.Value, format.Index, enquotedString, out tokenLen))
{
result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadQuote), ch);
+ StringBuilderCache.Release(enquotedString);
return (false);
}
format.Index += tokenLen - 1;
@@ -4213,7 +4214,7 @@ new DS[] { DS.ERROR, DS.TX_NNN, DS.TX_NNN, DS.TX_NNN, DS.ERROR, DS.ERROR,
// Some cultures uses space in the quoted string. E.g. Spanish has long date format as:
// "dddd, dd' de 'MMMM' de 'yyyy". When inner spaces flag is set, we should skip whitespaces if there is space
// in the quoted string.
- String quotedStr = enquotedString.ToString();
+ String quotedStr = StringBuilderCache.GetStringAndRelease(enquotedString);
for (int i = 0; i < quotedStr.Length; i++)
{
diff --git a/src/mscorlib/shared/System/Globalization/TimeSpanParse.cs b/src/mscorlib/shared/System/Globalization/TimeSpanParse.cs
index 6e7d784abe..8f511b71a5 100644
--- a/src/mscorlib/shared/System/Globalization/TimeSpanParse.cs
+++ b/src/mscorlib/shared/System/Globalization/TimeSpanParse.cs
@@ -1292,15 +1292,18 @@ namespace System.Globalization
case '\'':
case '\"':
- StringBuilder enquotedString = new StringBuilder();
+ StringBuilder enquotedString = StringBuilderCache.Acquire();
if (!DateTimeParse.TryParseQuoteString(format.AsReadOnlySpan(), i, enquotedString, out tokenLen))
{
+ StringBuilderCache.Release(enquotedString);
return result.SetFailure(ParseFailureKind.FormatWithParameter, nameof(SR.Format_BadQuote), ch);
}
if (!ParseExactLiteral(ref tokenizer, enquotedString))
{
+ StringBuilderCache.Release(enquotedString);
return result.SetFailure(ParseFailureKind.Format, nameof(SR.Format_InvalidString));
}
+ StringBuilderCache.Release(enquotedString);
break;
case '%':