Kaydet (Commit) 5e02c782 authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka Kaydeden (comit) GitHub

bpo-31410: Optimized calling wrapper and classmethod descriptors. (#3481)

üst b3a77964
...@@ -296,7 +296,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, ...@@ -296,7 +296,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
PyObject *kwds) PyObject *kwds)
{ {
Py_ssize_t argc; Py_ssize_t argc;
PyObject *self, *func, *result, **stack; PyObject *self, *result;
/* Make sure that the first argument is acceptable as 'self' */ /* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args)); assert(PyTuple_Check(args));
...@@ -330,20 +330,38 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args, ...@@ -330,20 +330,38 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
return NULL; return NULL;
} }
func = PyCFunction_NewEx(descr->d_method, self, NULL); result = _PyMethodDef_RawFastCallDict(descr->d_method, self,
if (func == NULL) &PyTuple_GET_ITEM(args, 1), argc - 1,
return NULL; kwds);
stack = &PyTuple_GET_ITEM(args, 1); result = _Py_CheckFunctionResult((PyObject *)descr, result, NULL);
result = _PyObject_FastCallDict(func, stack, argc - 1, kwds);
Py_DECREF(func);
return result; return result;
} }
Py_LOCAL_INLINE(PyObject *)
wrapperdescr_raw_call(PyWrapperDescrObject *descr, PyObject *self,
PyObject *args, PyObject *kwds)
{
wrapperfunc wrapper = descr->d_base->wrapper;
if (descr->d_base->flags & PyWrapperFlag_KEYWORDS) {
wrapperfunc_kwds wk = (wrapperfunc_kwds)wrapper;
return (*wk)(self, args, descr->d_wrapped, kwds);
}
if (kwds != NULL && (!PyDict_Check(kwds) || PyDict_GET_SIZE(kwds) != 0)) {
PyErr_Format(PyExc_TypeError,
"wrapper %s() takes no keyword arguments",
descr->d_base->name);
return NULL;
}
return (*wrapper)(self, args, descr->d_wrapped);
}
static PyObject * static PyObject *
wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
{ {
Py_ssize_t argc; Py_ssize_t argc;
PyObject *self, *func, *result, **stack; PyObject *self, *result;
/* Make sure that the first argument is acceptable as 'self' */ /* Make sure that the first argument is acceptable as 'self' */
assert(PyTuple_Check(args)); assert(PyTuple_Check(args));
...@@ -369,16 +387,16 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds) ...@@ -369,16 +387,16 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
return NULL; return NULL;
} }
func = PyWrapper_New((PyObject *)descr, self); args = PyTuple_GetSlice(args, 1, argc);
if (func == NULL) if (args == NULL) {
return NULL; return NULL;
}
stack = &PyTuple_GET_ITEM(args, 1); result = wrapperdescr_raw_call(descr, self, args, kwds);
result = _PyObject_FastCallDict(func, stack, argc - 1, kwds); Py_DECREF(args);
Py_DECREF(func);
return result; return result;
} }
static PyObject * static PyObject *
method_get_doc(PyMethodDescrObject *descr, void *closure) method_get_doc(PyMethodDescrObject *descr, void *closure)
{ {
...@@ -1167,21 +1185,7 @@ static PyGetSetDef wrapper_getsets[] = { ...@@ -1167,21 +1185,7 @@ static PyGetSetDef wrapper_getsets[] = {
static PyObject * static PyObject *
wrapper_call(wrapperobject *wp, PyObject *args, PyObject *kwds) wrapper_call(wrapperobject *wp, PyObject *args, PyObject *kwds)
{ {
wrapperfunc wrapper = wp->descr->d_base->wrapper; return wrapperdescr_raw_call(wp->descr, wp->self, args, kwds);
PyObject *self = wp->self;
if (wp->descr->d_base->flags & PyWrapperFlag_KEYWORDS) {
wrapperfunc_kwds wk = (wrapperfunc_kwds)wrapper;
return (*wk)(self, args, wp->descr->d_wrapped, kwds);
}
if (kwds != NULL && (!PyDict_Check(kwds) || PyDict_GET_SIZE(kwds) != 0)) {
PyErr_Format(PyExc_TypeError,
"wrapper %s() takes no keyword arguments",
wp->descr->d_base->name);
return NULL;
}
return (*wrapper)(self, args, wp->descr->d_wrapped);
} }
static int static int
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment