From: Stefan Behnel Date: Sat, 7 Dec 2013 07:24:56 +0000 (+0100) Subject: discard useless (PyObject*) casts from values of builtin types which are PyObject... X-Git-Tag: 0.20b1~149 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0c6e62fd1aeac71e6aee500a941b1c09d412b312;p=platform%2Fupstream%2Fpython-cython.git discard useless (PyObject*) casts from values of builtin types which are PyObject* internally anyway (saves lots of C code) --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 53d457f..0d66c07 100644 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -3760,9 +3760,13 @@ def typecast(to_type, from_type, expr_code): # Return expr_code cast to a C type which can be # assigned to to_type, assuming its existing C type # is from_type. - if to_type is from_type or \ - (not to_type.is_pyobject and assignable_from(to_type, from_type)): - return expr_code + if (to_type is from_type or + (not to_type.is_pyobject and assignable_from(to_type, from_type))): + return expr_code + elif (to_type is py_object_type and from_type and + from_type.is_builtin_type and from_type.name != 'type'): + # no cast needed, builtins are PyObject* already + return expr_code else: #print "typecast: to", to_type, "from", from_type ### return to_type.cast_code(expr_code)