From ccf63b52d362bb2d13aafef4793dcab484d553de Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Sun, 2 Apr 2023 15:00:35 -0700 Subject: [PATCH] Inline HashCode.Combine polyfill (#2280) --- src/Sentry/Internal/Polyfills.cs | 29 ----------------------------- src/Sentry/MeasurementUnit.cs | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src/Sentry/Internal/Polyfills.cs b/src/Sentry/Internal/Polyfills.cs index c4962ef971..2e263babaa 100644 --- a/src/Sentry/Internal/Polyfills.cs +++ b/src/Sentry/Internal/Polyfills.cs @@ -1,34 +1,5 @@ // Polyfills to bridge the missing APIs in older targets. -#if NETFRAMEWORK || NETSTANDARD2_0 -namespace System -{ - internal static class HashCode - { - public static int Combine(T1 value1, T2 value2) - { - unchecked - { - var hashCode = value1 != null ? value1.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (value2 != null ? value2.GetHashCode() : 0); - return hashCode; - } - } - - public static int Combine(T1 value1, T2 value2, T3 value3) - { - unchecked - { - var hashCode = value1 != null ? value1.GetHashCode() : 0; - hashCode = (hashCode * 397) ^ (value2 != null ? value2.GetHashCode() : 0); - hashCode = (hashCode * 397) ^ (value3 != null ? value3.GetHashCode() : 0); - return hashCode; - } - } - } -} -#endif - #if NETFRAMEWORK namespace System.Net.Http.Headers { diff --git a/src/Sentry/MeasurementUnit.cs b/src/Sentry/MeasurementUnit.cs index 2fe9776f09..86e9307258 100644 --- a/src/Sentry/MeasurementUnit.cs +++ b/src/Sentry/MeasurementUnit.cs @@ -82,7 +82,21 @@ internal static MeasurementUnit Parse(string? name) public override bool Equals(object? obj) => obj is MeasurementUnit other && Equals(other); /// - public override int GetHashCode() => HashCode.Combine(_unit, _name, _unit?.GetType()); + 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 + } /// /// Returns true if the operands are equal. @@ -93,4 +107,4 @@ internal static MeasurementUnit Parse(string? name) /// Returns true if the operands are not equal. /// public static bool operator !=(MeasurementUnit left, MeasurementUnit right) => !left.Equals(right); -} \ No newline at end of file +}