-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Currently string interpolation when all of the parts are strings prefers to lower to a string.Concat call when there's a string.Concat overload with the exact same number of string parameters. Beyond that, it falls back to using normal interpolation mechanisms. Now that in .NET 9 there's a string.Concat(params ReadOnlySpan<string>)
overload, it'd be nice if string interpolation preferred to use that overload when it's available, when all the parts are strings, and when there isn't a better overload of string.Concat available. This statement is invalidated by the new params span overload, which can support passing in all of the strings without an allocation:
roslyn/src/Compilers/CSharp/Portable/Binder/Binder_InterpolatedString.cs
Lines 231 to 233 in 9177306
// 4. The string is composed of more than 4 components that are all strings themselves. We can turn this into a single | |
// call to string.Concat. We prefer the builder over this because the builder can use pooling to avoid new allocations, while this | |
// call will need to allocate a param array. |
cc: @333fred