From eb0263f18ff407df8ada8e75ee413d1e63cffcea Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Thu, 6 Apr 2017 10:29:14 -0400 Subject: [PATCH] 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 --- .../Net/Http/Unix/CurlHandler.CurlResponseMessage.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs b/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs index 15d04d920f4..486338cb039 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/Unix/CurlHandler.CurlResponseMessage.cs @@ -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)); } }