From 06b5ea5c35881f38c12663c3631e00e4553b7aa8 Mon Sep 17 00:00:00 2001 From: Phil Garcia Date: Tue, 26 Jun 2018 22:03:49 -0700 Subject: [PATCH] Applying PR feedback Commit migrated from https://github.com/dotnet/coreclr/commit/d1d26ac8fd6aabbfe655de03bf0ee3ecb2d096cd --- .../src/Internal/Runtime/CompilerServices/Unsafe.cs | 11 +++++++++++ src/libraries/System.Private.CoreLib/src/System/Double.cs | 2 +- src/libraries/System.Private.CoreLib/src/System/Single.cs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs index aeff3ce..03d3f85 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/Runtime/CompilerServices/Unsafe.cs @@ -358,6 +358,17 @@ namespace Internal.Runtime.CompilerServices } /// + /// Reinterprets the given location as a reference to a value of type . + /// + [Intrinsic] + [NonVersionable] + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ref T AsRef(in T source) + { + throw new PlatformNotSupportedException(); + } + + /// /// Determines the byte offset from origin to target from the given references. /// [Intrinsic] diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index 308dda5..69da2e3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -226,7 +226,7 @@ namespace System [MethodImpl(MethodImplOptions.AggressiveInlining)] // 64-bit constants make the IL unusually large that makes the inliner to reject the method public override int GetHashCode() { - var bits = BitConverter.DoubleToInt64Bits(m_value); + var bits = Unsafe.As(ref Unsafe.AsRef(in m_value)); // Optimized check for IsNan() || IsZero() if (((bits - 1) & 0x7FFFFFFFFFFFFFFF) >= 0x7FF0000000000000) diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index d62ff9c..7dddb02 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -217,7 +217,7 @@ namespace System public override int GetHashCode() { - var bits = BitConverter.SingleToInt32Bits(m_value); + var bits = Unsafe.As(ref Unsafe.AsRef(in m_value)); // Optimized check for IsNan() || IsZero() if (((bits - 1) & 0x7FFFFFFF) >= 0x7F800000) -- 2.7.4