GetStreamAsync:
The GetContentAsync<T> helper was only being used for GetStreamAsync, but was taking a delegate as an argument to compute the stream result. That delegate takes up space in the state machine. We can instead just eliminate the delegate and make the GetContentAsync<T> method specific to streams, avoiding the delegate entirely. This reduces the state machine size on 64-bit from 96 to 88 bytes.
GetStringAsync / GetByteArrayAsync:
Both of these were implemented with an async method that took a delegate with which to determine the results. They also only involved a single await, in which case ContinueWith is cheaper in allocations, and they're simple enough to just use ContinueWith. So do so.
Commit migrated from https://github.com/dotnet/corefx/commit/b68308b2637e7edad561954b73cc8251850c3910
Currently the same async method handles both the buffered and unbuffered cases, which means even for the unbuffered case, the state machine needs to hold the relevant fields for the buffered case. This commit makes it more pay for play by splitting it into two methods. This reduces the size of the unbuffered state machine by 20% (on 64-bit from 120 bytes to 96 bytes).
Commit migrated from https://github.com/dotnet/corefx/commit/d85d630677621f623ed8d1cd9feb207f56bd0e91
We were using an async method to store and return the results from CreateContentReadStreamAsync, putting the resulting Stream into a field typed as Stream. This required having an async method to unwrap the result of of CreateContentReadStreamAsync, which in the best case (when CreateContentReadStreamAsync completes synchronously) would result in just a Task<Stream> allocation, and in the worst case (when CreatecontentReadStreamAsync completes asynchronously) would result in allocations for that async method's machinery. We can instead just store the Task<Stream> in the field instead of the Stream, and avoid those allocations entirely. (This also avoids an extra Task allocation each time the same stream is retrieved, though that's not particularly common.)
Commit migrated from https://github.com/dotnet/corefx/commit/7301572be85ddca88f6af2186736b33129cc4ced
Now that the base Stream.CopyToAsync has been optimized with ArrayPool and that LimitMemoryStream has its own optimized CopyToAsync override, we're better off using those and deleting most of the custom code in StreamToStreamCopy.
Commit migrated from https://github.com/dotnet/corefx/commit/7f3a155ec11a265d5e4cff4a1da46aba0323fd61
The base MemoryStream's CopyToAsync implementation only provides its optimizations when the concrete type of the stream is MemoryStream and not for derived streams. This commit adds a similar optimization to to LimitMemoryStream, such that it'll write its whole buffer to the destination in a single write.
Commit migrated from https://github.com/dotnet/corefx/commit/23b4fa71707970c7828af237fcee7ac0407f88be
A new CancellationTokenSource is currently always allocated, which then also means that the data structures inside the CTS that are lazily-initialized on first use will end up getting allocated as well for each operation. But if the supplied user's token isn't cancelable and there's no timeout, we can avoid these allocations.
Commit migrated from https://github.com/dotnet/corefx/commit/b967c767dfec8ab866dfb503b1b79b7892ec6a73
* Json changes for updating to new CLR
* Take new CoreCLR
Uses new copy of FileStream from CoreCLR
Moves FileStream to System.Runtime
Forwards from old locations
Various workarounds/fixes
* Update to CoreCLR beta-24704-03
Commit migrated from https://github.com/dotnet/corefx/commit/bd667b3e719ff84110d9b3c8c087a678337aa5a5
Added an HttpVersionInternal to be used by the higher-stack libraries that need things beyond HttpVersion.Version10/Version11 and/or that have builds targeting versioning of System.Net.Primitives that doesn't have the newly exposed HttpVersion. This can be removed once all of those libraries have all of their builds targeting the updated primitives lib.
Commit migrated from https://github.com/dotnet/corefx/commit/119ae03ddc2ce49511f10b02fb39818aab0aa577
We previously made a pass through corefx to use nameof with argument exceptions. Since then, a lot more code has come into the repo, and not all argument exceptions were converted at the time. We also previously missed a bunch of places where helpers were used to throw the exceptions. This does another pass through corefx to catch most of the remaining occurrences.
Commit migrated from https://github.com/dotnet/corefx/commit/08609e84ab068d09a6e72b5906bb5282e444ae2e