From 0bc3d7b7b1d544ddad5c5cc73d270d6dfe41a93b Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 16 Mar 2010 12:23:55 -0700 Subject: [PATCH] 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. --- Cython/Compiler/PyrexTypes.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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); } -- 2.26.2