Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up calling :class:`types.MethodType` by adding a vectorcall

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need a news here

implementation of the constructor generated by Argument Clinic.
10 changes: 6 additions & 4 deletions Objects/classobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ PyMethod_Self(PyObject *im)


static PyObject *
method_vectorcall(PyObject *method, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
method_instance_vectorcall(PyObject *method, PyObject *const *args,
size_t nargsf, PyObject *kwnames)
{
assert(Py_IS_TYPE(method, &PyMethod_Type));

Expand Down Expand Up @@ -78,7 +78,7 @@ PyMethod_New(PyObject *func, PyObject *self)
im->im_weakreflist = NULL;
im->im_func = Py_NewRef(func);
im->im_self = Py_NewRef(self);
im->vectorcall = method_vectorcall;
im->vectorcall = method_instance_vectorcall;
_PyObject_GC_TRACK(im);
return (PyObject *)im;
}
Expand Down Expand Up @@ -182,6 +182,7 @@ method_getattro(PyObject *obj, PyObject *name)
}

/*[clinic input]
@vectorcall
@classmethod
method.__new__ as method_new

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than rename the other function lets do as method_type_new here (which keeps this delta from needing to touch method_vectorcall

function: object
Expand All @@ -193,7 +194,7 @@ Create a bound instance method object.

static PyObject *
method_new_impl(PyTypeObject *type, PyObject *function, PyObject *instance)
/*[clinic end generated code: output=d33ef4ebf702e1f7 input=4e32facc3c3108ae]*/
/*[clinic end generated code: output=d33ef4ebf702e1f7 input=5e5e5a509ac9bc99]*/
{
if (!PyCallable_Check(function)) {
PyErr_SetString(PyExc_TypeError,
Expand Down Expand Up @@ -332,6 +333,7 @@ PyTypeObject PyMethod_Type = {
.tp_getset = method_getset,
.tp_descr_get = method_descr_get,
.tp_new = method_new,
.tp_vectorcall = method_vectorcall,
};

/* ------------------------------------------------------------------------
Expand Down
29 changes: 28 additions & 1 deletion Objects/clinic/classobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading