From 656991e8a23a65cd41f3037a778679159f2aaeee Mon Sep 17 00:00:00 2001 From: Bouke Haarsma Date: Tue, 16 Jul 2024 09:24:25 +0200 Subject: [PATCH] Use HashCode from Microsoft.Bcl.HashCode --- Directory.Packages.props | 1 + Source/SuperLinq.Async/SuperLinq.Async.csproj | 1 + Source/SuperLinq/KeyValuePairEqualityComparer.cs | 4 ---- Source/SuperLinq/SuperLinq.csproj | 1 + Source/SuperLinq/ValueTupleEqualityComparer.cs | 4 ---- Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs | 4 ---- 6 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index b2afa1ed..a785a008 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -20,6 +20,7 @@ + diff --git a/Source/SuperLinq.Async/SuperLinq.Async.csproj b/Source/SuperLinq.Async/SuperLinq.Async.csproj index ad4e44fd..37d92ad8 100644 --- a/Source/SuperLinq.Async/SuperLinq.Async.csproj +++ b/Source/SuperLinq.Async/SuperLinq.Async.csproj @@ -125,6 +125,7 @@ + <_Parameter1>SuperLinq.Async.Test diff --git a/Source/SuperLinq/KeyValuePairEqualityComparer.cs b/Source/SuperLinq/KeyValuePairEqualityComparer.cs index ce598185..5f2cd97c 100644 --- a/Source/SuperLinq/KeyValuePairEqualityComparer.cs +++ b/Source/SuperLinq/KeyValuePairEqualityComparer.cs @@ -48,12 +48,8 @@ public bool Equals(KeyValuePair x, KeyValuePair y) = && _valueComparer.Equals(x.Value, y.Value); public int GetHashCode(KeyValuePair obj) => -#if NETCOREAPP HashCode.Combine( _keyComparer.GetHashCode(obj.Key!), _valueComparer.GetHashCode(obj.Value!)); -#else - _keyComparer.GetHashCode(obj.Key) * 397 ^ _valueComparer.GetHashCode(obj.Value); -#endif } } diff --git a/Source/SuperLinq/SuperLinq.csproj b/Source/SuperLinq/SuperLinq.csproj index 98ce9be2..12bdf0a4 100644 --- a/Source/SuperLinq/SuperLinq.csproj +++ b/Source/SuperLinq/SuperLinq.csproj @@ -164,6 +164,7 @@ + <_Parameter1>SuperLinq.Test diff --git a/Source/SuperLinq/ValueTupleEqualityComparer.cs b/Source/SuperLinq/ValueTupleEqualityComparer.cs index d55e1de4..e8f11e3d 100644 --- a/Source/SuperLinq/ValueTupleEqualityComparer.cs +++ b/Source/SuperLinq/ValueTupleEqualityComparer.cs @@ -87,12 +87,8 @@ public bool Equals( && _comparer2.Equals(x.Item2, y.Item2); public int GetHashCode((T1, T2) obj) => -#if NETCOREAPP HashCode.Combine( _comparer1.GetHashCode(obj.Item1!), _comparer2.GetHashCode(obj.Item2!)); -#else - _comparer1.GetHashCode(obj.Item1) * 397 ^ _comparer2.GetHashCode(obj.Item2); -#endif } } diff --git a/Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs b/Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs index 8946c252..23c6e862 100644 --- a/Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs +++ b/Tests/SuperLinq.Test/ValueTupleEqualityComparerTest.cs @@ -79,11 +79,7 @@ public void ValueTupleEqualityComparerWithTwoTypeArgsShouldGetHashCode() var comparer = ValueTupleEqualityComparer.Create(comparer1: null, comparer2: null); ValueTuple first = new(1, 2); var firstHashCode = comparer.GetHashCode(first); -#if NETCOREAPP var expectedHashCode = HashCode.Combine(1.GetHashCode(), 2.GetHashCode()); -#else - var expectedHashCode = 1.GetHashCode() * 397 ^ 2.GetHashCode(); -#endif Assert.Equal(expectedHashCode, firstHashCode); } }