From: Justin Van Patten Date: Wed, 22 Nov 2017 23:34:03 +0000 (-0800) Subject: StringBuilder: Use Decimal.TryFormat (#15170) X-Git-Tag: accepted/tizen/base/20180629.140029~484 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9aafd0c570ac5d4a2aa12d1f45da828d820e9013;p=platform%2Fupstream%2Fcoreclr.git StringBuilder: Use Decimal.TryFormat (#15170) --- diff --git a/src/mscorlib/shared/System/Text/StringBuilder.cs b/src/mscorlib/shared/System/Text/StringBuilder.cs index da0182b..8d3961a 100644 --- a/src/mscorlib/shared/System/Text/StringBuilder.cs +++ b/src/mscorlib/shared/System/Text/StringBuilder.cs @@ -1040,7 +1040,18 @@ namespace System.Text public StringBuilder Append(double value) => Append(value.ToString()); - public StringBuilder Append(decimal value) => Append(value.ToString()); + public StringBuilder Append(decimal value) + { + if (value.TryFormat(RemainingCurrentChunk, out int charsWritten)) + { + m_ChunkLength += charsWritten; + return this; + } + else + { + return Append(value.ToString()); + } + } [CLSCompliant(false)] public StringBuilder Append(ushort value) diff --git a/src/mscorlib/src/System/Decimal.cs b/src/mscorlib/src/System/Decimal.cs index 2ea0ca5..998a73d 100644 --- a/src/mscorlib/src/System/Decimal.cs +++ b/src/mscorlib/src/System/Decimal.cs @@ -60,7 +60,7 @@ namespace System [Serializable] [System.Runtime.Versioning.NonVersionable] // This only applies to field layout [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] - public partial struct Decimal : IFormattable, IComparable, IConvertible, IComparable, IEquatable, IDeserializationCallback + public partial struct Decimal : IFormattable, IComparable, IConvertible, IComparable, IEquatable, IDeserializationCallback, ISpanFormattable { // Sign mask for the flags field. A value of zero in this bit indicates a // positive Decimal value, and a value of one in this bit indicates a