Remove some StringBuilder-related allocations from System.Net.Http by stephentoub · Pull Request #30508 · dotnet/corefx (original) (raw)
picenka21 pushed a commit to picenka21/runtime that referenced this pull request
- Remove boxing and ToString allocations from RangeHeaderValue.ToString
The current code uses ToString(object), boxng the long? and then calling ToString on it. By instead first checking whether the value is null and only calling ToString(long), we avoid both the box and the string allocations, for both From and To, relying on StringBuilder's ability to format a long directly into its buffer.
- Avoid StringBuilder/char[]/string allocation/copy in DumpHeaders
We can just write into the existing StringBuilder rather than creating a new one, appending to that, copying it to a string, and then appending that string to the original.
Commit migrated from dotnet/corefx@8c0487b