Skip to content

Commit

Permalink
Always inline number conversions (#112061)
Browse files Browse the repository at this point in the history
* Mark TryConvertFrom as AggressiveInlining

* Cover TryConvertTo
  • Loading branch information
hez2010 authored Feb 2, 2025
1 parent 5a8f405 commit 4bd597f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Decimal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,7 @@ static bool INumberBase<decimal>.TryConvertFromTruncating<TOther>(TOther value,
return TryConvertFrom(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertFrom<TOther>(TOther value, out decimal result)
where TOther : INumberBase<TOther>
{
Expand Down Expand Up @@ -1722,6 +1723,7 @@ static bool INumberBase<decimal>.TryConvertToTruncating<TOther>(decimal value, [
return TryConvertTo(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertTo<TOther>(decimal value, [MaybeNullWhen(false)] out TOther result)
where TOther : INumberBase<TOther>
{
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ static bool INumberBase<double>.TryConvertFromTruncating<TOther>(TOther value, o
return TryConvertFrom(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertFrom<TOther>(TOther value, out double result)
where TOther : INumberBase<TOther>
{
Expand Down Expand Up @@ -1378,6 +1379,7 @@ static bool INumberBase<double>.TryConvertToTruncating<TOther>(double value, [Ma
return TryConvertTo(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertTo<TOther>(double value, [MaybeNullWhen(false)] out TOther result)
where TOther : INumberBase<TOther>
{
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Half.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1928,6 +1928,7 @@ static bool INumberBase<Half>.TryConvertFromTruncating<TOther>(TOther value, out
return TryConvertFrom(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertFrom<TOther>(TOther value, out Half result)
where TOther : INumberBase<TOther>
{
Expand Down Expand Up @@ -2077,6 +2078,7 @@ static bool INumberBase<Half>.TryConvertToTruncating<TOther>(Half value, [MaybeN
return TryConvertTo(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertTo<TOther>(Half value, [MaybeNullWhen(false)] out TOther result)
where TOther : INumberBase<TOther>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,7 @@ static bool INumberBase<NFloat>.TryConvertFromTruncating<TOther>(TOther value, o
return TryConvertFrom(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertFrom<TOther>(TOther value, out NFloat result)
where TOther : INumberBase<TOther>
{
Expand Down Expand Up @@ -1649,6 +1650,7 @@ static bool INumberBase<NFloat>.TryConvertToTruncating<TOther>(NFloat value, [Ma
return TryConvertTo(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertTo<TOther>(NFloat value, [MaybeNullWhen(false)] out TOther result)
where TOther : INumberBase<TOther>
{
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ static bool INumberBase<float>.TryConvertFromTruncating<TOther>(TOther value, ou
return TryConvertFrom(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertFrom<TOther>(TOther value, out float result)
where TOther : INumberBase<TOther>
{
Expand Down Expand Up @@ -1397,6 +1398,7 @@ static bool INumberBase<float>.TryConvertToTruncating<TOther>(float value, [Mayb
return TryConvertTo(value, out result);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool TryConvertTo<TOther>(float value, [MaybeNullWhen(false)] out TOther result)
where TOther : INumberBase<TOther>
{
Expand Down

0 comments on commit 4bd597f

Please sign in to comment.