@@ -30,7 +30,6 @@ private Converter()
30
30
private static Type flagsType ;
31
31
private static Type boolType ;
32
32
private static Type typeType ;
33
- private static IntPtr decimalCtor ;
34
33
private static IntPtr dateTimeCtor ;
35
34
private static IntPtr timeSpanCtor ;
36
35
private static IntPtr tzInfoCtor ;
@@ -50,16 +49,9 @@ static Converter()
50
49
boolType = typeof ( Boolean ) ;
51
50
typeType = typeof ( Type ) ;
52
51
53
-
54
- IntPtr decimalMod = Runtime . PyImport_ImportModule ( "decimal" ) ;
55
- if ( decimalMod == null ) throw new PythonException ( ) ;
56
-
57
52
IntPtr dateTimeMod = Runtime . PyImport_ImportModule ( "datetime" ) ;
58
53
if ( dateTimeMod == null ) throw new PythonException ( ) ;
59
54
60
- decimalCtor = Runtime . PyObject_GetAttrString ( decimalMod , "Decimal" ) ;
61
- if ( decimalCtor == null ) throw new PythonException ( ) ;
62
-
63
55
dateTimeCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "datetime" ) ;
64
56
if ( dateTimeCtor == null ) throw new PythonException ( ) ;
65
57
@@ -308,17 +300,9 @@ internal static IntPtr ToPython(object value, Type type)
308
300
return Runtime . PyLong_FromUnsignedLongLong ( ( ulong ) value ) ;
309
301
310
302
case TypeCode . Decimal :
311
- IntPtr mod = Runtime . PyImport_ImportModule ( "decimal" ) ;
312
- IntPtr ctor = Runtime . PyObject_GetAttrString ( mod , "Decimal" ) ;
313
-
314
- string d2s = ( ( decimal ) value ) . ToString ( nfi ) ;
315
- IntPtr d2p = Runtime . PyString_FromString ( d2s ) ;
316
- IntPtr args = Runtime . PyTuple_New ( 1 ) ;
317
- Runtime . PyTuple_SetItem ( args , 0 , d2p ) ;
318
- var returnDecimal = Runtime . PyObject_CallObject ( decimalCtor , args ) ;
319
- // clean up
320
- Runtime . XDecref ( args ) ;
321
- return returnDecimal ;
303
+ // C# decimal to python decimal has a big impact on performance
304
+ // so we will use C# double and python float
305
+ return Runtime . PyFloat_FromDouble ( decimal . ToDouble ( ( decimal ) value ) ) ;
322
306
323
307
case TypeCode . DateTime :
324
308
var datetime = ( DateTime ) value ;
0 commit comments