Commit ef95d354 authored by Stefan Behnel's avatar Stefan Behnel

Include PyLong_AsDouble() in optimised float() implementations.

parent 95624a28
......@@ -430,7 +430,7 @@ def init_builtins():
global list_type, tuple_type, dict_type, set_type, frozenset_type
global bytes_type, str_type, unicode_type, basestring_type, slice_type
global float_type, bool_type, type_type, complex_type, bytearray_type
global float_type, long_type, bool_type, type_type, complex_type, bytearray_type
type_type = builtin_scope.lookup('type').type
list_type = builtin_scope.lookup('list').type
tuple_type = builtin_scope.lookup('tuple').type
......@@ -444,6 +444,7 @@ def init_builtins():
basestring_type = builtin_scope.lookup('basestring').type
bytearray_type = builtin_scope.lookup('bytearray').type
float_type = builtin_scope.lookup('float').type
long_type = builtin_scope.lookup('long').type
bool_type = builtin_scope.lookup('bool').type
complex_type = builtin_scope.lookup('complex').type
......
......@@ -2642,6 +2642,8 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
elif func_arg.type is Builtin.str_type:
cfunc_name = "__Pyx_PyString_AsDouble"
utility_code_name = 'pystring_as_double'
elif func_arg.type is Builtin.long_type:
cfunc_name = "PyLong_AsDouble"
else:
arg = func_arg # no need for an additional None check
cfunc_name = "__Pyx_PyObject_AsDouble"
......@@ -2656,7 +2658,7 @@ class OptimizeBuiltinCalls(Visitor.NodeRefCleanupMixin,
self.PyObject_AsDouble_func_type,
args = [arg],
is_temp = node.is_temp,
utility_code = load_c_utility(utility_code_name),
utility_code = load_c_utility(utility_code_name) if utility_code_name else None,
py_name = "float")
PyNumber_Int_func_type = PyrexTypes.CFuncType(
......
......@@ -591,8 +591,9 @@ static double __Pyx__PyObject_AsDouble(PyObject* obj); /* proto */
PyFloat_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
#else
#define __Pyx_PyObject_AsDouble(obj) \
((likely(PyFloat_CheckExact(obj))) ? \
PyFloat_AS_DOUBLE(obj) : __Pyx__PyObject_AsDouble(obj))
((likely(PyFloat_CheckExact(obj))) ? PyFloat_AS_DOUBLE(obj) : \
likely(PyLong_CheckExact(obj)) ? \
PyLong_AsDouble(obj) : __Pyx__PyObject_AsDouble(obj))
#endif
/////////////// pyobject_as_double ///////////////
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment