Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Replace HashHelpers.Combine with HashCode.Combine in netcoreapp projects #40935

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
<Compile Include="$(CommonPath)\System\Drawing\KnownColorTable.cs">
<Link>System\Drawing\KnownColorTable.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\CoreLib\System\Numerics\Hashing\HashHelpers.cs">
<Link>Common\System\Numerics\Hashing\HashHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Drawing\SystemColors.cs">
<Link>System\Drawing\SystemColors.cs</Link>
</Compile>
Expand Down
4 changes: 1 addition & 3 deletions src/System.Drawing.Primitives/src/System/Drawing/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
stephentoub marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
1 change: 0 additions & 1 deletion src/System.Drawing.Primitives/src/System/Drawing/Point.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/System.Drawing.Primitives/src/System/Drawing/PointF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/System.Drawing.Primitives/src/System/Drawing/Size.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
1 change: 0 additions & 1 deletion src/System.Drawing.Primitives/src/System/Drawing/SizeF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 0 additions & 3 deletions src/System.Memory/src/System.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
</ItemGroup>
<ItemGroup>
<!-- Common or Common-branched source files -->
<Compile Include="$(CommonPath)\CoreLib\System\Numerics\Hashing\HashHelpers.cs">
<Link>Common\System\Collections\HashHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\System\Buffers\ArrayBufferWriter.cs">
<Link>Common\System\Buffers\ArrayBufferWriter.cs</Link>
</Compile>
Expand Down
3 changes: 1 addition & 2 deletions src/System.Memory/src/System/SequencePosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,6 +51,6 @@ public SequencePosition(object? @object, int integer)

/// <inheritdoc />
[EditorBrowsable(EditorBrowsableState.Never)]
public override int GetHashCode() => HashHelpers.Combine(_object?.GetHashCode() ?? 0, _integer);
public override int GetHashCode() => HashCode.Combine(_object?.GetHashCode() ?? 0, _integer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
</PropertyGroup>
<!-- Shared -->
<ItemGroup>
<Compile Include="$(CommonPath)\CoreLib\System\Numerics\Hashing\HashHelpers.cs">
<Link>Common\System\Numerics\Hashing\HashHelpers.cs</Link>
</Compile>
<Compile Include="$(CommonPath)\CoreLib\System\Runtime\CompilerServices\IntrinsicAttribute.cs">
<Link>System\Runtime\CompilerServices\IntrinsicAttribute.cs</Link>
</Compile>
Expand Down
5 changes: 1 addition & 4 deletions src/System.Numerics.Vectors/src/System/Numerics/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -54,9 +53,7 @@ public static Vector2 One
/// <returns>The hash code.</returns>
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());
}

/// <summary>
Expand Down
6 changes: 1 addition & 5 deletions src/System.Numerics.Vectors/src/System/Numerics/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -59,10 +58,7 @@ public static Vector3 One
/// <returns>The hash code.</returns>
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());
}

/// <summary>
Expand Down
7 changes: 1 addition & 6 deletions src/System.Numerics.Vectors/src/System/Numerics/Vector4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -62,11 +61,7 @@ public static Vector4 One
/// <returns>The hash code.</returns>
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());
}

/// <summary>
Expand Down
18 changes: 3 additions & 15 deletions src/System.Numerics.Vectors/tests/GenericVectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,21 +466,9 @@ static GenericVectorTests()
public void GetHashCodeDouble() { TestGetHashCode<double>(); }
private void TestGetHashCode<T>() where T : struct
{
T[] values1 = GenerateRandomValuesForVector<T>();
Vector<T> v1 = new Vector<T>(values1);
int hash = v1.GetHashCode();

int expected = 0;
for (int g = 0; g < Vector<T>.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<T>();
Vector<T> v = new Vector<T>(values);
Assert.Equal(v.GetHashCode(), v.GetHashCode());
}

[Fact]
Expand Down
18 changes: 3 additions & 15 deletions src/System.Numerics.Vectors/tests/GenericVectorTests.tt
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,9 @@ namespace System.Numerics.Tests
#>
private void TestGetHashCode<T>() where T : struct
{
T[] values1 = GenerateRandomValuesForVector<T>();
Vector<T> v1 = new Vector<T>(values1);
int hash = v1.GetHashCode();

int expected = 0;
for (int g = 0; g < Vector<T>.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<T>();
Vector<T> v = new Vector<T>(values);
Assert.Equal(v.GetHashCode(), v.GetHashCode());
}

<#
Expand Down