@@ -29,7 +29,6 @@ private Converter()
2929 private static Type flagsType ;
3030 private static Type boolType ;
3131 private static Type typeType ;
32- private static IntPtr decimalCtor ;
3332 private static IntPtr dateTimeCtor ;
3433 private static IntPtr timeSpanCtor ;
3534 private static IntPtr tzInfoCtor ;
@@ -49,15 +48,9 @@ static Converter()
4948 boolType = typeof ( Boolean ) ;
5049 typeType = typeof ( Type ) ;
5150
52- IntPtr decimalMod = Runtime . PyImport_ImportModule ( "decimal" ) ;
53- if ( decimalMod == null ) throw new PythonException ( ) ;
54-
5551 IntPtr dateTimeMod = Runtime . PyImport_ImportModule ( "datetime" ) ;
5652 if ( dateTimeMod == null ) throw new PythonException ( ) ;
5753
58- decimalCtor = Runtime . PyObject_GetAttrString ( decimalMod , "Decimal" ) ;
59- if ( decimalCtor == null ) throw new PythonException ( ) ;
60-
6154 dateTimeCtor = Runtime . PyObject_GetAttrString ( dateTimeMod , "datetime" ) ;
6255 if ( dateTimeCtor == null ) throw new PythonException ( ) ;
6356
@@ -281,14 +274,9 @@ internal static IntPtr ToPython(object value, Type type)
281274 return Runtime . PyLong_FromUnsignedLongLong ( ( ulong ) value ) ;
282275
283276 case TypeCode . Decimal :
284- string d2s = ( ( decimal ) value ) . ToString ( nfi ) ;
285- IntPtr d2p = Runtime . PyString_FromString ( d2s ) ;
286- IntPtr decimalArgs = Runtime . PyTuple_New ( 1 ) ;
287- Runtime . PyTuple_SetItem ( decimalArgs , 0 , d2p ) ;
288- var returnDecimal = Runtime . PyObject_CallObject ( decimalCtor , decimalArgs ) ;
289- // clean up
290- Runtime . XDecref ( decimalArgs ) ;
291- return returnDecimal ;
277+ // C# decimal to python decimal has a big impact on performance
278+ // so we will use C# double and python float
279+ return Runtime . PyFloat_FromDouble ( decimal . ToDouble ( ( decimal ) value ) ) ;
292280
293281 case TypeCode . DateTime :
294282 var datetime = ( DateTime ) value ;
0 commit comments