call_function(): document PyMethod optimization

This commit is contained in:
Victor Stinner 2016-11-28 18:32:31 +01:00
parent 213cc388c7
commit b69ee8c386
1 changed files with 5 additions and 1 deletions

View File

@ -4736,7 +4736,11 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
} }
else { else {
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) { if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {
/* optimize access to bound methods */ /* Optimize access to bound methods. Reuse the Python stack
to pass 'self' as the first argument, replace 'func'
with 'self'. It avoids the creation of a new temporary tuple
for arguments (to replace func with self) when the method uses
FASTCALL. */
PyObject *self = PyMethod_GET_SELF(func); PyObject *self = PyMethod_GET_SELF(func);
Py_INCREF(self); Py_INCREF(self);
func = PyMethod_GET_FUNCTION(func); func = PyMethod_GET_FUNCTION(func);