summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-01-18 09:38:09 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-01-18 09:38:09 (GMT)
commitc52572319cbd50adff85050a54122c25239a516d (patch)
tree41e964e6b6a25c655496561a32ce97c0f14ce253 /Objects/descrobject.c
parent35ecebe165b1f64cb94c1b947db1d0b07e6db69b (diff)
downloadcpython-c52572319cbd50adff85050a54122c25239a516d.zip
cpython-c52572319cbd50adff85050a54122c25239a516d.tar.gz
cpython-c52572319cbd50adff85050a54122c25239a516d.tar.bz2
Optimize methoddescr_call(): avoid temporary PyCFunction
Issue #29259, #29263. methoddescr_call() creates a PyCFunction object, call it and the destroy it. Add a new _PyMethodDef_RawFastCallDict() method to avoid the temporary PyCFunction object.
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index ed39891..a254a2a 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -210,15 +210,15 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
}
static PyObject *
-methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
+methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwargs)
{
- Py_ssize_t argc;
- PyObject *self, *func, *result, **stack;
+ Py_ssize_t nargs;
+ PyObject *self, *result;
/* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args));
- argc = PyTuple_GET_SIZE(args);
- if (argc < 1) {
+ nargs = PyTuple_GET_SIZE(args);
+ if (nargs < 1) {
PyErr_Format(PyExc_TypeError,
"descriptor '%V' of '%.100s' "
"object needs an argument",
@@ -239,12 +239,10 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
return NULL;
}
- func = PyCFunction_NewEx(descr->d_method, self, NULL);
- if (func == NULL)
- return NULL;
- stack = &PyTuple_GET_ITEM(args, 1);
- result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
- Py_DECREF(func);
+ result = _PyMethodDef_RawFastCallDict(descr->d_method, self,
+ &PyTuple_GET_ITEM(args, 1), nargs - 1,
+ kwargs);
+ result = _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
return result;
}