From: Raymond Hettinger Date: Fri, 9 Oct 2015 05:34:08 +0000 (-0400) Subject: Hoist constant expression out of the inner loop. X-Git-Tag: v3.6.0a1~1290 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd5f0e8c1cf633a238c10e1d3199c0d572a4df1d;p=python Hoist constant expression out of the inner loop. --- diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3f2e2c004e..3c8f1e9841 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -469,6 +469,7 @@ filter_next(filterobject *lz) PyObject *it = lz->it; long ok; PyObject *(*iternext)(PyObject *); + int checktrue = lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type; iternext = *Py_TYPE(it)->tp_iternext; for (;;) { @@ -476,12 +477,11 @@ filter_next(filterobject *lz) if (item == NULL) return NULL; - if (lz->func == Py_None || lz->func == (PyObject *)&PyBool_Type) { + if (checktrue) { ok = PyObject_IsTrue(item); } else { PyObject *good; - good = PyObject_CallFunctionObjArgs(lz->func, - item, NULL); + good = PyObject_CallFunctionObjArgs(lz->func, item, NULL); if (good == NULL) { Py_DECREF(item); return NULL;