From 0a86d0ce5a5b0ac36c37139768d38c83f6405928 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Sun, 8 Sep 2019 23:00:13 -0400 Subject: [PATCH] Replace HashHelpers.Combine with HashCode.Combine in netcoreapp projects --- .../src/System.Drawing.Primitives.csproj | 3 --- .../src/System/Drawing/Color.cs | 4 +--- .../src/System/Drawing/Point.cs | 1 - .../src/System/Drawing/PointF.cs | 1 - .../src/System/Drawing/Rectangle.cs | 1 - .../src/System/Drawing/RectangleF.cs | 1 - .../src/System/Drawing/Size.cs | 1 - .../src/System/Drawing/SizeF.cs | 1 - src/System.Memory/src/System.Memory.csproj | 3 --- .../src/System/SequencePosition.cs | 3 +-- .../src/System.Numerics.Vectors.csproj | 3 --- .../src/System/Numerics/Vector2.cs | 5 +---- .../src/System/Numerics/Vector3.cs | 6 +----- .../src/System/Numerics/Vector4.cs | 7 +------ .../tests/GenericVectorTests.cs | 18 +++--------------- .../tests/GenericVectorTests.tt | 18 +++--------------- 16 files changed, 11 insertions(+), 65 deletions(-) diff --git a/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj b/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj index fecccd3ac77d..47d3a4ab4ddd 100644 --- a/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj +++ b/src/System.Drawing.Primitives/src/System.Drawing.Primitives.csproj @@ -42,9 +42,6 @@ System\Drawing\KnownColorTable.cs - - Common\System\Numerics\Hashing\HashHelpers.cs - System\Drawing\SystemColors.cs diff --git a/src/System.Drawing.Primitives/src/System/Drawing/Color.cs b/src/System.Drawing.Primitives/src/System/Drawing/Color.cs index 21731bd16252..4f702e84fd6f 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/Color.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/Color.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Diagnostics; -using System.Numerics.Hashing; using System.Runtime.CompilerServices; namespace System.Drawing @@ -580,8 +579,7 @@ public override int GetHashCode() if (name != null & !IsKnownColor) return name.GetHashCode(); - return HashHelpers.Combine( - HashHelpers.Combine(value.GetHashCode(), state.GetHashCode()), knownColor.GetHashCode()); + return HashCode.Combine(value.GetHashCode(), state.GetHashCode(), knownColor.GetHashCode()); } } } diff --git a/src/System.Drawing.Primitives/src/System/Drawing/Point.cs b/src/System.Drawing.Primitives/src/System/Drawing/Point.cs index 525e52ca7a07..c8e92c14ab32 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/Point.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/Point.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Drawing.Primitives/src/System/Drawing/PointF.cs b/src/System.Drawing.Primitives/src/System/Drawing/PointF.cs index 9cad5fcb4605..6d469f4ec61a 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/PointF.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/PointF.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs b/src/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs index adae4d1700bd..9680fc20c323 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs b/src/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs index 9844bffea6fb..e649effa8ab5 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/RectangleF.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Drawing.Primitives/src/System/Drawing/Size.cs b/src/System.Drawing.Primitives/src/System/Drawing/Size.cs index e69c62716e7f..1a315cbd451d 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/Size.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/Size.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Drawing.Primitives/src/System/Drawing/SizeF.cs b/src/System.Drawing.Primitives/src/System/Drawing/SizeF.cs index ed0699f5f7bb..5d4cb5eb8307 100644 --- a/src/System.Drawing.Primitives/src/System/Drawing/SizeF.cs +++ b/src/System.Drawing.Primitives/src/System/Drawing/SizeF.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; -using System.Numerics.Hashing; namespace System.Drawing { diff --git a/src/System.Memory/src/System.Memory.csproj b/src/System.Memory/src/System.Memory.csproj index 26352dd0020e..307a28bc2c3c 100644 --- a/src/System.Memory/src/System.Memory.csproj +++ b/src/System.Memory/src/System.Memory.csproj @@ -34,9 +34,6 @@ - - Common\System\Collections\HashHelpers.cs - Common\System\Buffers\ArrayBufferWriter.cs diff --git a/src/System.Memory/src/System/SequencePosition.cs b/src/System.Memory/src/System/SequencePosition.cs index 6eedc0d7b660..13aeabe34ec7 100644 --- a/src/System.Memory/src/System/SequencePosition.cs +++ b/src/System.Memory/src/System/SequencePosition.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Numerics.Hashing; using System.ComponentModel; namespace System @@ -52,6 +51,6 @@ public SequencePosition(object? @object, int integer) /// [EditorBrowsable(EditorBrowsableState.Never)] - public override int GetHashCode() => HashHelpers.Combine(_object?.GetHashCode() ?? 0, _integer); + public override int GetHashCode() => HashCode.Combine(_object?.GetHashCode() ?? 0, _integer); } } diff --git a/src/System.Numerics.Vectors/src/System.Numerics.Vectors.csproj b/src/System.Numerics.Vectors/src/System.Numerics.Vectors.csproj index 42b5ccdaa7f0..cd68fd4f46c5 100644 --- a/src/System.Numerics.Vectors/src/System.Numerics.Vectors.csproj +++ b/src/System.Numerics.Vectors/src/System.Numerics.Vectors.csproj @@ -11,9 +11,6 @@ - - Common\System\Numerics\Hashing\HashHelpers.cs - System\Runtime\CompilerServices\IntrinsicAttribute.cs diff --git a/src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs b/src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs index 1b6e5240794b..868dba3b6236 100644 --- a/src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs +++ b/src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Globalization; -using System.Numerics.Hashing; using System.Runtime.CompilerServices; using System.Text; @@ -54,9 +53,7 @@ public static Vector2 One /// The hash code. public override readonly int GetHashCode() { - int hash = this.X.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - return hash; + return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode()); } /// diff --git a/src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs b/src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs index 2bc838c01480..5e1994dce054 100644 --- a/src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs +++ b/src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Globalization; -using System.Numerics.Hashing; using System.Runtime.CompilerServices; using System.Text; @@ -59,10 +58,7 @@ public static Vector3 One /// The hash code. public override readonly int GetHashCode() { - int hash = this.X.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - hash = HashHelpers.Combine(hash, this.Z.GetHashCode()); - return hash; + return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode(), this.Z.GetHashCode()); } /// diff --git a/src/System.Numerics.Vectors/src/System/Numerics/Vector4.cs b/src/System.Numerics.Vectors/src/System/Numerics/Vector4.cs index dc19850fca31..4f6b3439cd9a 100644 --- a/src/System.Numerics.Vectors/src/System/Numerics/Vector4.cs +++ b/src/System.Numerics.Vectors/src/System/Numerics/Vector4.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System.Globalization; -using System.Numerics.Hashing; using System.Runtime.CompilerServices; using System.Text; @@ -62,11 +61,7 @@ public static Vector4 One /// The hash code. public override readonly int GetHashCode() { - int hash = this.X.GetHashCode(); - hash = HashHelpers.Combine(hash, this.Y.GetHashCode()); - hash = HashHelpers.Combine(hash, this.Z.GetHashCode()); - hash = HashHelpers.Combine(hash, this.W.GetHashCode()); - return hash; + return HashCode.Combine(this.X.GetHashCode(), this.Y.GetHashCode(), this.Z.GetHashCode(), this.W.GetHashCode()); } /// diff --git a/src/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/System.Numerics.Vectors/tests/GenericVectorTests.cs index e1f56f1cb37a..906fb9efe56a 100644 --- a/src/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -466,21 +466,9 @@ private void TestEqualsVector() where T : struct public void GetHashCodeDouble() { TestGetHashCode(); } private void TestGetHashCode() where T : struct { - T[] values1 = GenerateRandomValuesForVector(); - Vector v1 = new Vector(values1); - int hash = v1.GetHashCode(); - - int expected = 0; - for (int g = 0; g < Vector.Count; g++) - { - unchecked - { - uint shift5 = ((uint)expected << 5) | ((uint)expected >> 27); - expected = ((int)shift5 + expected) ^ v1[g].GetHashCode(); - } - } - - Assert.Equal(expected, hash); + T[] values = GenerateRandomValuesForVector(); + Vector v = new Vector(values); + Assert.Equal(v.GetHashCode(), v.GetHashCode()); } [Fact] diff --git a/src/System.Numerics.Vectors/tests/GenericVectorTests.tt b/src/System.Numerics.Vectors/tests/GenericVectorTests.tt index 0de0b74d1ed9..507763bb5f55 100644 --- a/src/System.Numerics.Vectors/tests/GenericVectorTests.tt +++ b/src/System.Numerics.Vectors/tests/GenericVectorTests.tt @@ -328,21 +328,9 @@ namespace System.Numerics.Tests #> private void TestGetHashCode() where T : struct { - T[] values1 = GenerateRandomValuesForVector(); - Vector v1 = new Vector(values1); - int hash = v1.GetHashCode(); - - int expected = 0; - for (int g = 0; g < Vector.Count; g++) - { - unchecked - { - uint shift5 = ((uint)expected << 5) | ((uint)expected >> 27); - expected = ((int)shift5 + expected) ^ v1[g].GetHashCode(); - } - } - - Assert.Equal(expected, hash); + T[] values = GenerateRandomValuesForVector(); + Vector v = new Vector(values); + Assert.Equal(v.GetHashCode(), v.GetHashCode()); } <#