[Python-checkins] cpython: Issue #27809: Use _PyObject_FastCallDict()

victor.stinner python-checkins at python.org
Mon Aug 22 17:22:19 EDT 2016


https://hg.python.org/cpython/rev/15eab21bf934
changeset:   102844:15eab21bf934
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Mon Aug 22 23:21:55 2016 +0200
summary:
  Issue #27809: Use _PyObject_FastCallDict()

Modify:

* builtin_sorted()
* classmethoddescr_call()
* methoddescr_call()
* wrapperdescr_call()

files:
  Objects/descrobject.c |  34 +++++++++---------------------
  Python/bltinmodule.c  |  15 ++++---------
  2 files changed, 15 insertions(+), 34 deletions(-)


diff --git a/Objects/descrobject.c b/Objects/descrobject.c
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -213,7 +213,7 @@
 methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
 {
     Py_ssize_t argc;
-    PyObject *self, *func, *result;
+    PyObject *self, *func, *result, **stack;
 
     /* Make sure that the first argument is acceptable as 'self' */
     assert(PyTuple_Check(args));
@@ -242,13 +242,8 @@
     func = PyCFunction_NewEx(descr->d_method, self, NULL);
     if (func == NULL)
         return NULL;
-    args = PyTuple_GetSlice(args, 1, argc);
-    if (args == NULL) {
-        Py_DECREF(func);
-        return NULL;
-    }
-    result = PyEval_CallObjectWithKeywords(func, args, kwds);
-    Py_DECREF(args);
+    stack = &PyTuple_GET_ITEM(args, 1);
+    result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
     Py_DECREF(func);
     return result;
 }
@@ -258,7 +253,7 @@
                       PyObject *kwds)
 {
     Py_ssize_t argc;
-    PyObject *self, *func, *result;
+    PyObject *self, *func, *result, **stack;
 
     /* Make sure that the first argument is acceptable as 'self' */
     assert(PyTuple_Check(args));
@@ -295,14 +290,9 @@
     func = PyCFunction_NewEx(descr->d_method, self, NULL);
     if (func == NULL)
         return NULL;
-    args = PyTuple_GetSlice(args, 1, argc);
-    if (args == NULL) {
-        Py_DECREF(func);
-        return NULL;
-    }
-    result = PyEval_CallObjectWithKeywords(func, args, kwds);
+    stack = &PyTuple_GET_ITEM(args, 1);
+    result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
     Py_DECREF(func);
-    Py_DECREF(args);
     return result;
 }
 
@@ -310,7 +300,7 @@
 wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
 {
     Py_ssize_t argc;
-    PyObject *self, *func, *result;
+    PyObject *self, *func, *result, **stack;
 
     /* Make sure that the first argument is acceptable as 'self' */
     assert(PyTuple_Check(args));
@@ -339,13 +329,9 @@
     func = PyWrapper_New((PyObject *)descr, self);
     if (func == NULL)
         return NULL;
-    args = PyTuple_GetSlice(args, 1, argc);
-    if (args == NULL) {
-        Py_DECREF(func);
-        return NULL;
-    }
-    result = PyEval_CallObjectWithKeywords(func, args, kwds);
-    Py_DECREF(args);
+
+    stack = &PyTuple_GET_ITEM(args, 1);
+    result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
     Py_DECREF(func);
     return result;
 }
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2087,10 +2087,11 @@
 static PyObject *
 builtin_sorted(PyObject *self, PyObject *args, PyObject *kwds)
 {
-    PyObject *newlist, *v, *seq, *keyfunc=NULL, *newargs;
+    PyObject *newlist, *v, *seq, *keyfunc=NULL, **newargs;
     PyObject *callable;
     static char *kwlist[] = {"iterable", "key", "reverse", 0};
     int reverse;
+    int nargs;
 
     /* args 1-3 should match listsort in Objects/listobject.c */
     if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oi:sorted",
@@ -2107,15 +2108,9 @@
         return NULL;
     }
 
-    newargs = PyTuple_GetSlice(args, 1, 4);
-    if (newargs == NULL) {
-        Py_DECREF(newlist);
-        Py_DECREF(callable);
-        return NULL;
-    }
-
-    v = PyObject_Call(callable, newargs, kwds);
-    Py_DECREF(newargs);
+    newargs = &PyTuple_GET_ITEM(args, 1);
+    nargs = PyTuple_GET_SIZE(args) - 1;
+    v = _PyObject_FastCallDict(callable, newargs, nargs, kwds);
     Py_DECREF(callable);
     if (v == NULL) {
         Py_DECREF(newlist);

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


More information about the Python-checkins mailing list