Avoid unnecessary copy in TextWriter.Write(string)#125595
Avoid unnecessary copy in TextWriter.Write(string)#125595logiclrd wants to merge 1 commit intodotnet:mainfrom
Conversation
…dOnlySpan<char> for the string data instead of copying it to a new char[].
|
|
|
Tagging subscribers to this area: @dotnet/area-system-io |
|
I notice that the |
|
I dug into one of those failures and found this: 😛 |
|
This is a behavioral change. It will change the virtual method called in derived class. Similar to #68800. |
Any derived class that cares about performance can override all these virtual methods. The base class has to be fully compatible that
It's the same as |
|
Mm, okay. The fact that the In my opinion, either it shouldn't be guaranteed by the implementation, or it should be documented. Unless there's documentation I'm unaware of (quite possible), the current state feels kind of hand-wavy. Is switching from |
There are more contracts implied by other rules beyond specific documentations. Given the history and other decisions in the area, the behavior around virtual methods is considered important.
It's probably because the behavior was such since .NET Framework 1.0. |
It's documented as a breaking change here:
Documentation or not, changing things like this is more or less guaranteed to break someone. Breaks for performance improvements are, in my opinion, hard to justify, especially when a derived type can simply override the implementation themselves if they are sure of the desired behavior. |
|
Fair enough :-) Thanks for taking the time to elaborate. |
This PR updates the
Write(string?)overload inTextWriter.csto avoid copying the string data.