-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use interpolated strings in place of StringBuilder.AppendFormat
where possible.
#62160
Use interpolated strings in place of StringBuilder.AppendFormat
where possible.
#62160
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
src/libraries/Microsoft.Extensions.DependencyInjection/src/CallSiteJsonFormatter.cs
Outdated
Show resolved
Hide resolved
...ies/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/Metrics/MetricsEventSource.cs
Outdated
Show resolved
Hide resolved
...s/System.Security.Cryptography.Xml/src/System/Security/Cryptography/Xml/SignedXmlDebugLog.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Speech/src/Internal/Synthesis/TextFragmentEngine.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
This PR converts all calls to
StringBuilder.AppendFormat
in non-test code to instead useStringBuilder.Append
with interpolated strings, taking advantage of the .NET 6 interpolated string handlers, that allocate zero intermediate objects, writing the characters directly to theStringBuilder
in our case.Call sites where the format strings were obtained from resources could not be optimized and were not changed.
Earlier frameworks might see a slightly decreased performance but the changed code does not seem to be performance-critical.