Skip to content

Commit

Permalink
Replace HashHelpers.Combine with HashCode.Combine in netcoreapp proje…
Browse files Browse the repository at this point in the history
…cts (dotnet/corefx#40935)

Commit migrated from dotnet/corefx@8c221ca
  • Loading branch information
stephentoub committed Sep 9, 2019
1 parent 1d084ac commit 8e061d8
Show file tree
Hide file tree
Showing 16 changed files with 11 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,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
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());
}
}
}
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
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
3 changes: 0 additions & 3 deletions src/libraries/System.Memory/src/System.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,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/libraries/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 @@ -10,9 +10,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
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
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
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/libraries/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/libraries/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

0 comments on commit 8e061d8

Please sign in to comment.