[Python-checkins] cpython: Hoist constant expression out of the inner loop.

raymond.hettinger python-checkins at python.org
Fri Oct 9 01:35:30 EDT 2015


https://hg.python.org/cpython/rev/1aae9b6a6929
changeset:   98614:1aae9b6a6929
user:        Raymond Hettinger <python at rcn.com>
date:        Fri Oct 09 01:34:08 2015 -0400
summary:
  Hoist constant expression out of the inner loop.

files:
  Python/bltinmodule.c |  6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)


diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -469,6 +469,7 @@
     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 @@
         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;

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list