forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use ValueStringBuilder to fix allocations in ToString() methods of Xd…
…sDateTime and XsdDuration (dotnet#64868) * Use ValueStringBuilder to fix allocations in XdsDateTime struct method ToString() * Use ValueStringBuilder in XsdDuration * Fix failing tests * Address feedback * Address feedback 2 * few more brackets rmoved * Use previous methods for formatting into 2/4/X digits as they are faster than AppendSpanFormattable Co-authored-by: Traian Zaprianov <[email protected]>
- Loading branch information
1 parent
55abc29
commit 9a050cd
Showing
7 changed files
with
110 additions
and
119 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/libraries/Common/src/System/Text/ValueStringBuilder.AppendSpanFormattable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace System.Text | ||
{ | ||
internal ref partial struct ValueStringBuilder | ||
{ | ||
internal void AppendSpanFormattable<T>(T value, string? format, IFormatProvider? provider) where T : ISpanFormattable | ||
{ | ||
if (value.TryFormat(_chars.Slice(_pos), out int charsWritten, format, provider)) | ||
{ | ||
_pos += charsWritten; | ||
} | ||
else | ||
{ | ||
Append(value.ToString(format, provider)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.