[Python-checkins] cpython: Backed out changeset 70f88b097f60 (map_next)

victor.stinner python-checkins at python.org
Tue Aug 23 18:55:43 EDT 2016


https://hg.python.org/cpython/rev/c647c4f1db9e
changeset:   102875:c647c4f1db9e
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Wed Aug 24 00:54:47 2016 +0200
summary:
  Backed out changeset 70f88b097f60 (map_next)

files:
  Python/bltinmodule.c |  50 ++++++++++---------------------
  1 files changed, 17 insertions(+), 33 deletions(-)


diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -1156,43 +1156,27 @@
 static PyObject *
 map_next(mapobject *lz)
 {
-    PyObject *small_stack[5];
-    PyObject **stack;
-    Py_ssize_t niters, nargs, i;
-    PyObject *result = NULL;
+    PyObject *val;
+    PyObject *argtuple;
+    PyObject *result;
+    Py_ssize_t numargs, i;
 
-    niters = PyTuple_GET_SIZE(lz->iters);
-    if (niters <= (Py_ssize_t)Py_ARRAY_LENGTH(small_stack)) {
-        stack = small_stack;
-    }
-    else {
-        stack = PyMem_Malloc(niters * sizeof(PyObject*));
-        if (stack == NULL) {
-            PyErr_NoMemory();
+    numargs = PyTuple_GET_SIZE(lz->iters);
+    argtuple = PyTuple_New(numargs);
+    if (argtuple == NULL)
+        return NULL;
+
+    for (i=0 ; i<numargs ; i++) {
+        PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
+        val = Py_TYPE(it)->tp_iternext(it);
+        if (val == NULL) {
+            Py_DECREF(argtuple);
             return NULL;
         }
+        PyTuple_SET_ITEM(argtuple, i, val);
     }
-
-    nargs = 0;
-    for (i=0; i < niters; i++) {
-        PyObject *it = PyTuple_GET_ITEM(lz->iters, i);
-        PyObject *val = Py_TYPE(it)->tp_iternext(it);
-        if (val == NULL) {
-            goto exit;
-        }
-        stack[i] = val;
-        nargs++;
-    }
-
-    result = _PyObject_FastCall(lz->func, stack, nargs);
-
-exit:
-    for (i=0; i < nargs; i++) {
-        Py_DECREF(stack[i]);
-    }
-    if (stack != small_stack) {
-        PyMem_Free(stack);
-    }
+    result = PyObject_Call(lz->func, argtuple, NULL);
+    Py_DECREF(argtuple);
     return result;
 }
 

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


More information about the Python-checkins mailing list