10000 gh-89013: Improve the performance of methodcaller (lazy version) by eendebakpt · Pull Request #107201 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-89013: Improve the performance of methodcaller (lazy version) #107201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 1, 2023
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
restore methodcaller_call
  • Loading branch information
eendebakpt committed Jul 21, 2023
commit 09e3ee329d799e22df8de6e7489caee97ac1ecbb
28 changes: 28 additions & 0 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,33 @@ methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg)
return 0;
}

static PyObject *
methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
{
PyObject *method, *obj, *result;

if (!_PyArg_NoKeywords("methodcaller", kw))
return NULL;
if (!_PyArg_CheckPositional("methodcaller", PyTuple_GET_SIZE(args), 1, 1))
return NULL;
obj = PyTuple_GET_ITEM(args, 0);
method = PyObject_GetAttr(obj, mc->name);
if (method == NULL)
return NULL;


PyObject *cargs = PyTuple_GetSlice(mc->xargs, 1, PyTuple_GET_SIZE(mc->xargs));
if (cargs == NULL) {
Py_DECREF(method);
return NULL;
}

result = PyObject_Call(method, cargs, mc->kwds);
Py_DECREF(cargs);
Py_DECREF(method);
return result;
}

static PyObject *
methodcaller_repr(methodcallerobject *mc)
{
Expand Down Expand Up @@ -1805,6 +1832,7 @@ r.name('date', foo=1).");
static PyType_Slot methodcaller_type_slots[] = {
{Py_tp_doc, (void *)methodcaller_doc},
{Py_tp_dealloc, methodcaller_dealloc},
{Py_tp_call, methodcaller_call},
{Py_tp_traverse, methodcaller_traverse},
{Py_tp_clear, methodcaller_clear},
{Py_tp_methods, methodcaller_methods},
Expand Down
0