Issue #27809: methodcaller_reduce() uses fast call

This commit is contained in:
Victor Stinner 2016-08-23 00:23:23 +02:00
parent 6412f4993a
commit 7e7823a037
1 changed files with 7 additions and 11 deletions

View File

@ -1111,6 +1111,8 @@ methodcaller_reduce(methodcallerobject *mc)
PyObject *functools; PyObject *functools;
PyObject *partial; PyObject *partial;
PyObject *constructor; PyObject *constructor;
PyObject *newargs[2];
_Py_IDENTIFIER(partial); _Py_IDENTIFIER(partial);
functools = PyImport_ImportModule("functools"); functools = PyImport_ImportModule("functools");
if (!functools) if (!functools)
@ -1119,17 +1121,11 @@ methodcaller_reduce(methodcallerobject *mc)
Py_DECREF(functools); Py_DECREF(functools);
if (!partial) if (!partial)
return NULL; return NULL;
newargs = PyTuple_New(2);
if (newargs == NULL) { newargs[0] = (PyObject *)Py_TYPE(mc);
Py_DECREF(partial); newargs[1] = mc->name;
return NULL; constructor = _PyObject_FastCallDict(partial, newargs, 2, mc->kwds);
}
Py_INCREF(Py_TYPE(mc));
PyTuple_SET_ITEM(newargs, 0, (PyObject *)Py_TYPE(mc));
Py_INCREF(mc->name);
PyTuple_SET_ITEM(newargs, 1, mc->name);
constructor = PyObject_Call(partial, newargs, mc->kwds);
Py_DECREF(newargs);
Py_DECREF(partial); Py_DECREF(partial);
return Py_BuildValue("NO", constructor, mc->args); return Py_BuildValue("NO", constructor, mc->args);
} }