Store _pendingReadRequest into a local for multiple accesses

It should not be possible by construction for _pendingReadRequest to become null in SignalComplete after we check it for nullness, as all access to it is protected by a lock.  But for good measure, store it into a local and use that local for subsequent accesses.  If nothing else, we can avoid an extra field access.


Commit migrated from https://github.com/dotnet/corefx/commit/7dc759724bd3da68ebe3756f1e3ffa9bd9266d2c
This commit is contained in:
Stephen Toub committed 2017-04-06 10:29:14 -04:00
1 parent 580e439dc7
commit eb0263f18f
1 file changed
+5 -4
@@ -393,12 +393,13 @@ namespace System.Net.Http
// If there's a pending read request, complete it, either with 0 bytes for success
// or with the exception/CancellationToken for failure.
if (_pendingReadRequest != null)
ReadState pendingRead = _pendingReadRequest;
if (pendingRead != null)
{
if (_completed == s_completionSentinel)
{
EventSourceTrace("Completing pending read with 0 bytes");
_pendingReadRequest.TrySetResult(0);
pendingRead.TrySetResult(0);
}
else
{
@@ -406,11 +407,11 @@ namespace System.Net.Http
OperationCanceledException oce = _completed as OperationCanceledException;
if (oce != null)
{
_pendingReadRequest.TrySetCanceled(oce.CancellationToken);
pendingRead.TrySetCanceled(oce.CancellationToken);
}
else
{
_pendingReadRequest.TrySetException(MapToReadWriteIOException(_completed, isRead: true));
pendingRead.TrySetException(MapToReadWriteIOException(_completed, isRead: true));
}
}