@@ -30,7 +30,6 @@ private Converter()
3030 private static Type flagsType ;
3131 private static Type boolType ;
3232 private static Type typeType ;
33- private static IntPtr decimalCtor ;
3433 private static IntPtr dateTimeCtor ;
3534 private static IntPtr timeSpanCtor ;
3635 private static IntPtr tzInfoCtor ;
@@ -50,16 +49,9 @@ static Converter()
5049 boolType = typeof ( Boolean ) ;
5150 typeType = typeof ( Type ) ;
5251
53-
54- IntPtr decimalMod = Runtime . PyImport_ImportModule ( "decimal" ) ;
55- if ( decimalMod == null ) throw new PythonException ( ) ;
56-
5752 IntPtr dateTimeMod = Runtime . PyImport_ImportModule ( "datetime" ) ;
5853 if ( dateTimeMod == null ) throw new PythonException ( ) ;
5954
60- decimalCtor = Runtime . PyObject_GetAttrString ( decimalMod , "Decimal" ) ;
61- if ( decimalCtor == null ) throw new PythonException ( ) ;
62-
6355 dateTimeCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "datetime" ) ;
6456 if ( dateTimeCtor == null ) throw new PythonException ( ) ;
6557
@@ -308,17 +300,9 @@ internal static IntPtr ToPython(object value, Type type)
308300 return Runtime . PyLong_FromUnsignedLongLong ( ( ulong ) value ) ;
309301
310302 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 ) ) ;
322306
323307 case TypeCode . DateTime :
324308 var datetime = ( DateTime ) value ;
0 commit comments