Use ReferenceEquals instead of Delegate.op_Equality for sentinel checks
authorJustin Van Patten <jvp@justinvp.com>
Thu, 4 May 2017 22:05:38 +0000 (15:05 -0700)
committerJustin Van Patten <jvp@justinvp.com>
Thu, 4 May 2017 22:05:38 +0000 (15:05 -0700)
The reference equality check is more efficient than
Delegate.op_Equality.

Commit migrated from https://github.com/dotnet/coreclr/commit/e42e2ce0d6422fc74175e032842aaa5bb38e2112

src/coreclr/src/mscorlib/shared/System/IO/FileStream.Windows.cs

index 7c09ae1..c036ee6 100644 (file)
@@ -1599,7 +1599,7 @@ namespace System.IO
             {
                 var awaitable = (AsyncCopyToAwaitable)ThreadPoolBoundHandle.GetNativeOverlappedState(pOVERLAP);
 
-                Debug.Assert(awaitable._continuation != s_sentinel, "Sentinel must not have already been set as the continuation");
+                Debug.Assert(!ReferenceEquals(awaitable._continuation, s_sentinel), "Sentinel must not have already been set as the continuation");
                 awaitable._errorCode = errorCode;
                 awaitable._numBytes = numBytes;
 
@@ -1617,15 +1617,15 @@ namespace System.IO
             }
 
             public AsyncCopyToAwaitable GetAwaiter() => this;
-            public bool IsCompleted => _continuation == s_sentinel;
+            public bool IsCompleted => ReferenceEquals(_continuation, s_sentinel);
             public void GetResult() { }
             public void OnCompleted(Action continuation) => UnsafeOnCompleted(continuation);
             public void UnsafeOnCompleted(Action continuation)
             {
-                if (_continuation == s_sentinel ||
+                if (ReferenceEquals(_continuation, s_sentinel) ||
                     Interlocked.CompareExchange(ref _continuation, continuation, null) != null)
                 {
-                    Debug.Assert(_continuation == s_sentinel, $"Expected continuation set to s_sentinel, got ${_continuation}");
+                    Debug.Assert(ReferenceEquals(_continuation, s_sentinel), $"Expected continuation set to s_sentinel, got ${_continuation}");
                     Task.Run(continuation);
                 }
             }