Commit 985a8508 authored by Stefan Behnel's avatar Stefan Behnel

optimise PyLong + const double also in Py2

parent 70b8e3c1
...@@ -553,13 +553,15 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYT ...@@ -553,13 +553,15 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYT
if (likely(PyFloat_CheckExact({{pyval}}))) { if (likely(PyFloat_CheckExact({{pyval}}))) {
{{fval}} = PyFloat_AS_DOUBLE({{pyval}}); {{fval}} = PyFloat_AS_DOUBLE({{pyval}});
} else } else
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (likely(PyInt_CheckExact({{pyval}}))) { if (likely(PyInt_CheckExact({{pyval}}))) {
{{fval}} = (double) PyInt_AS_LONG({{pyval}}); {{fval}} = (double) PyInt_AS_LONG({{pyval}});
} else } else
#endif #endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_USE_PYLONG_INTERNALS
if (likely(PyLong_CheckExact({{pyval}}))) { if (likely(PyLong_CheckExact({{pyval}}))) {
#if PY_MAJOR_VERSION >= 3 && CYTHON_USE_PYLONG_INTERNALS
switch (Py_SIZE({{pyval}})) { switch (Py_SIZE({{pyval}})) {
case -1: {{fval}} = -(double)((PyLongObject*){{pyval}})->ob_digit[0]; break; case -1: {{fval}} = -(double)((PyLongObject*){{pyval}})->ob_digit[0]; break;
case 0: {{fval}} = 0.0; break; case 0: {{fval}} = 0.0; break;
...@@ -568,8 +570,11 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYT ...@@ -568,8 +570,11 @@ static PyObject* __Pyx_PyFloat_{{op}}{{order}}(PyObject *op1, PyObject *op2, CYT
if (unlikely({{fval}} == -1 && PyErr_Occurred())) return NULL; if (unlikely({{fval}} == -1 && PyErr_Occurred())) return NULL;
break; break;
} }
} else #else
{{fval}} = PyLong_AsDouble({{pyval}});
if (unlikely({{fval}} == -1 && PyErr_Occurred())) return NULL;
#endif #endif
} else
return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2); return (inplace ? PyNumber_InPlace{{op}} : PyNumber_{{op}})(op1, op2);
return PyFloat_FromDouble(a {{ '+' if op == 'Add' else '-' }} b); return PyFloat_FromDouble(a {{ '+' if op == 'Add' else '-' }} b);
} }
......
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