Skip to content

Commit

Permalink
Chore/hashcode combine (#2283)
Browse files Browse the repository at this point in the history
* Revert "Inline HashCode.Combine polyfill (#2280)"

This reverts commit ccf63b5.

* Simplify
  • Loading branch information
mattjohnsonpint committed Apr 3, 2023
1 parent 062db11 commit 2fc6e54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
11 changes: 11 additions & 0 deletions src/Sentry/Internal/Polyfills.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
// Polyfills to bridge the missing APIs in older targets.

#if NETFRAMEWORK || NETSTANDARD2_0
namespace System
{
internal static class HashCode
{
public static int Combine<T1, T2>(T1 value1, T2 value2) => (value1, value2).GetHashCode();
public static int Combine<T1, T2, T3>(T1 value1, T2 value2, T3 value3) => (value1, value2, value3).GetHashCode();
}
}
#endif

#if NETFRAMEWORK
namespace System.Net.Http.Headers
{
Expand Down
18 changes: 2 additions & 16 deletions src/Sentry/MeasurementUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,7 @@ internal static MeasurementUnit Parse(string? name)
public override bool Equals(object? obj) => obj is MeasurementUnit other && Equals(other);

/// <inheritdoc />
public override int GetHashCode()
{
var unitType = _unit?.GetType();
#if NETSTANDARD2_0 || NETFRAMEWORK
unchecked
{
var hashCode = _unit != null ? _unit.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ (_name != null ? _name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (unitType != null ? unitType.GetHashCode() : 0);
return hashCode;
}
#else
return HashCode.Combine(_unit, _name, unitType);
#endif
}
public override int GetHashCode() => HashCode.Combine(_unit, _name, _unit?.GetType());

/// <summary>
/// Returns true if the operands are equal.
Expand All @@ -107,4 +93,4 @@ public override int GetHashCode()
/// Returns true if the operands are not equal.
/// </summary>
public static bool operator !=(MeasurementUnit left, MeasurementUnit right) => !left.Equals(right);
}
}

0 comments on commit 2fc6e54

Please sign in to comment.