Use HashCode.Add rather than HashCode.Combine (#2200)
authorJohn Tur <john-tur@outlook.com>
Tue, 28 Jan 2020 13:46:57 +0000 (09:46 -0400)
committerStephen Toub <stoub@microsoft.com>
Tue, 28 Jan 2020 13:46:57 +0000 (08:46 -0500)
src/libraries/System.Private.CoreLib/src/System/Array.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector128_1.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector256_1.cs
src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics/Vector64_1.cs

index ed9fe71..2226b48 100644 (file)
@@ -375,14 +375,14 @@ namespace System
             if (comparer == null)
                 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.comparer);
 
-            int ret = 0;
+            HashCode hashCode = default;
 
             for (int i = (this.Length >= 8 ? this.Length - 8 : 0); i < this.Length; i++)
             {
-                ret = HashCode.Combine(ret, comparer.GetHashCode(GetValue(i)!));
+                hashCode.Add(comparer.GetHashCode(GetValue(i)!));
             }
 
-            return ret;
+            return hashCode.ToHashCode();
         }
 
         // Searches an array for a given element using a binary search algorithm.
index 46c9323..b62b3e8 100644 (file)
@@ -155,14 +155,14 @@ namespace System.Runtime.Intrinsics
         {
             ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
 
-            int hashCode = 0;
+            HashCode hashCode = default;
 
             for (int i = 0; i < Count; i++)
             {
-                hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
+                hashCode.Add(this.GetElement(i).GetHashCode());
             }
 
-            return hashCode;
+            return hashCode.ToHashCode();
         }
 
         /// <summary>Converts the current instance to an equivalent string representation.</summary>
index 09962fc..e7aa1b7 100644 (file)
@@ -156,14 +156,14 @@ namespace System.Runtime.Intrinsics
         {
             ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
 
-            int hashCode = 0;
+            HashCode hashCode = default;
 
             for (int i = 0; i < Count; i++)
             {
-                hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
+                hashCode.Add(this.GetElement(i).GetHashCode());
             }
 
-            return hashCode;
+            return hashCode.ToHashCode();
         }
 
         /// <summary>Converts the current instance to an equivalent string representation.</summary>
index 3c35b31..98084fd 100644 (file)
@@ -109,14 +109,14 @@ namespace System.Runtime.Intrinsics
         {
             ThrowHelper.ThrowForUnsupportedVectorBaseType<T>();
 
-            int hashCode = 0;
+            HashCode hashCode = default;
 
             for (int i = 0; i < Count; i++)
             {
-                hashCode = HashCode.Combine(hashCode, this.GetElement(i).GetHashCode());
+                hashCode.Add(this.GetElement(i).GetHashCode());
             }
 
-            return hashCode;
+            return hashCode.ToHashCode();
         }
 
         /// <summary>Converts the current instance to an equivalent string representation.</summary>