Optimize Half.Equals (#41554)
authorHuo Yaoyuan <huoyaoyuan@hotmail.com>
Mon, 31 Aug 2020 07:08:21 +0000 (15:08 +0800)
committerGitHub <noreply@github.com>
Mon, 31 Aug 2020 07:08:21 +0000 (00:08 -0700)
src/libraries/System.Private.CoreLib/src/System/Half.cs

index 1840f3c..98852c4 100644 (file)
@@ -422,11 +422,9 @@ namespace System
         /// </summary>
         public bool Equals(Half other)
         {
-            if (this == other)
-            {
-                return true;
-            }
-            return IsNaN(this) && IsNaN(other);
+            return _value == other._value
+                || AreZero(this, other)
+                || (IsNaN(this) && IsNaN(other));
         }
 
         /// <summary>