From 4bd597ffde128555b4ff017e87c60adc2fedd178 Mon Sep 17 00:00:00 2001 From: Steve Date: Mon, 3 Feb 2025 02:13:18 +0900 Subject: [PATCH] Always inline number conversions (#112061) * Mark TryConvertFrom as AggressiveInlining * Cover TryConvertTo --- src/libraries/System.Private.CoreLib/src/System/Decimal.cs | 2 ++ src/libraries/System.Private.CoreLib/src/System/Double.cs | 2 ++ src/libraries/System.Private.CoreLib/src/System/Half.cs | 2 ++ .../src/System/Runtime/InteropServices/NFloat.cs | 2 ++ src/libraries/System.Private.CoreLib/src/System/Single.cs | 2 ++ 5 files changed, 10 insertions(+) diff --git a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs index 351597114398c8..c9e03939b8ae82 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Decimal.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Decimal.cs @@ -1573,6 +1573,7 @@ static bool INumberBase.TryConvertFromTruncating(TOther value, return TryConvertFrom(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertFrom(TOther value, out decimal result) where TOther : INumberBase { @@ -1722,6 +1723,7 @@ static bool INumberBase.TryConvertToTruncating(decimal value, [ return TryConvertTo(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertTo(decimal value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase { diff --git a/src/libraries/System.Private.CoreLib/src/System/Double.cs b/src/libraries/System.Private.CoreLib/src/System/Double.cs index c4ed8ed65587ad..a5adb8057f6a5e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Double.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Double.cs @@ -1229,6 +1229,7 @@ static bool INumberBase.TryConvertFromTruncating(TOther value, o return TryConvertFrom(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertFrom(TOther value, out double result) where TOther : INumberBase { @@ -1378,6 +1379,7 @@ static bool INumberBase.TryConvertToTruncating(double value, [Ma return TryConvertTo(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertTo(double value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase { diff --git a/src/libraries/System.Private.CoreLib/src/System/Half.cs b/src/libraries/System.Private.CoreLib/src/System/Half.cs index fab95058ccd261..3ef63767f242d8 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Half.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Half.cs @@ -1928,6 +1928,7 @@ static bool INumberBase.TryConvertFromTruncating(TOther value, out return TryConvertFrom(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertFrom(TOther value, out Half result) where TOther : INumberBase { @@ -2077,6 +2078,7 @@ static bool INumberBase.TryConvertToTruncating(Half value, [MaybeN return TryConvertTo(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertTo(Half value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase { diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs index 5939bc9e159450..5e2fb905df195c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/NFloat.cs @@ -1410,6 +1410,7 @@ static bool INumberBase.TryConvertFromTruncating(TOther value, o return TryConvertFrom(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertFrom(TOther value, out NFloat result) where TOther : INumberBase { @@ -1649,6 +1650,7 @@ static bool INumberBase.TryConvertToTruncating(NFloat value, [Ma return TryConvertTo(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertTo(NFloat value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase { diff --git a/src/libraries/System.Private.CoreLib/src/System/Single.cs b/src/libraries/System.Private.CoreLib/src/System/Single.cs index 38b9b389f7d9c3..ef991d4aea3ea0 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Single.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Single.cs @@ -1248,6 +1248,7 @@ static bool INumberBase.TryConvertFromTruncating(TOther value, ou return TryConvertFrom(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertFrom(TOther value, out float result) where TOther : INumberBase { @@ -1397,6 +1398,7 @@ static bool INumberBase.TryConvertToTruncating(float value, [Mayb return TryConvertTo(value, out result); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool TryConvertTo(float value, [MaybeNullWhen(false)] out TOther result) where TOther : INumberBase {