From: Robert Bradshaw Date: Tue, 16 Mar 2010 19:23:55 +0000 (-0700) Subject: Another object -> bint optimization. X-Git-Tag: 0.13.beta0~277 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0bc3d7b7b1d544ddad5c5cc73d270d6dfe41a93b;p=cython.git Another object -> bint optimization. __Pyx_PyObject_IsTrue now has only a single branch, even at -O0. (The bitwise | is intentional.) This is only a 2.5% or so speedup in my microbenchmarks, but it's something. --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 3ef2eef9..19dd80dc 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -2485,12 +2485,13 @@ static CYTHON_INLINE size_t __Pyx_PyInt_AsSize_t(PyObject*); """ + type_conversion_predeclarations +# Note: __Pyx_PyObject_IsTrue is written to minimize branching. type_conversion_functions = """ /* Type Conversion Functions */ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { - if (x == Py_True) return 1; - else if ((x == Py_False) || (x == Py_None)) return 0; + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); }