@@ -1465,7 +1465,12 @@ private Decimal128(ulong highBits, ulong lowBits)
1465
1465
/// <param name="value">The value.</param>
1466
1466
public Decimal128 ( decimal value )
1467
1467
{
1468
+ #if NET6_0_OR_GREATER
1469
+ Span < int > bits = stackalloc int [ 4 ] ;
1470
+ _ = decimal . GetBits ( value , bits ) ;
1471
+ #else
1468
1472
var bits = decimal . GetBits ( value ) ;
1473
+ #endif
1469
1474
var isNegative = ( bits [ 3 ] & 0x80000000 ) != 0 ;
1470
1475
var scale = ( short ) ( ( bits [ 3 ] & 0x00FF0000 ) >> 16 ) ;
1471
1476
var exponent = ( short ) - scale ;
@@ -1904,7 +1909,12 @@ public int Compare(Decimal128 x, Decimal128 y)
1904
1909
{
1905
1910
var xType = GetDecimal128Type ( x ) ;
1906
1911
var yType = GetDecimal128Type ( y ) ;
1907
- var result = xType . CompareTo ( yType ) ;
1912
+ // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer
1913
+ #if NET6_0_OR_GREATER
1914
+ var result = Comparer < Decimal128Type > . Default . Compare ( xType , yType ) ;
1915
+ #else
1916
+ var result = ( ( int ) xType ) . CompareTo ( ( int ) yType ) ;
1917
+ #endif
1908
1918
if ( result == 0 && xType == Decimal128Type . Number )
1909
1919
{
1910
1920
return CompareNumbers ( x , y ) ;
@@ -1928,7 +1938,12 @@ private int CompareNumbers(Decimal128 x, Decimal128 y)
1928
1938
{
1929
1939
var xClass = GetNumberClass ( x ) ;
1930
1940
var yClass = GetNumberClass ( y ) ;
1931
- var result = xClass . CompareTo ( yClass ) ;
1941
+ // .NET Framework lacks some optimizations for enums that would result in boxing and lookup overhead for the default comparer
1942
+ #if NET6_0_OR_GREATER
1943
+ var result = Comparer < NumberClass > . Default . Compare ( xClass , yClass ) ;
1944
+ #else
1945
+ var result = ( ( int ) xClass ) . CompareTo ( ( int ) yClass ) ;
1946
+ #endif
1932
1947
if ( result == 0 )
1933
1948
{
1934
1949
if ( xClass == NumberClass . Negative )
0 commit comments