Use Stream's BeginReadInternal from FileStream (dotnet/coreclr#27737)
authorStephen Toub <stoub@microsoft.com>
Mon, 11 Nov 2019 19:10:20 +0000 (14:10 -0500)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2019 19:10:20 +0000 (14:10 -0500)
commit64856c64de96c77b10e10622ba906dcb4eb9c085
treefd7a1a9cb13274f4018d3f15d8168f8ca57dcf31
parent7078ee438b66dd8cdd9e1ae4a1981a3052c8d54e
Use Stream's BeginReadInternal from FileStream (dotnet/coreclr#27737)

FileStream has two modes, decided upon at construction time.  When it's created in non-async mode, the Read/WriteAsync methods end up queueing work items to invoke the synchronous Read/Write methods.  To do this, the base methods on Stream delegate to Begin/EndRead/Write (since they were around first) and then the resulting IAsyncResult is wrapped.  However, Stream has an optimization that checks to see whether the derived stream actually overrides Begin/EndXx, and if it doesn't, then it skips using those and goes straight to queueing a work item to Read/Write.  However, FileStream does override those, but when it delegates to the base implementation because it's in non-async mode (rather than because it's a type derived from FileStream), going through Begin/EndXx is just unnecessary overhead.  So, in the right circumstances, we can call to Stream's special helper instead.

Commit migrated from https://github.com/dotnet/coreclr/commit/e2741eb3358768e823d17f853bf17b08fda6bf58
src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs