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
inline methodcaller_clear
  • Loading branch information
eendebakpt committed Jul 30, 2023
commit ad7d6bd090a8434422b8e0218fd5b51a0f8371f4
17 changes: 7 additions & 10 deletions Modules/_operator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,12 +1556,13 @@ typedef struct {
vectorcallfunc vectorcall;
} methodcallerobject;

static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
static void* _methodcaller_initialize_vectorcall(methodcallerobject* mc)
{
PyObject* args = mc->xargs;
PyObject* kwds = mc->kwds;

Py_ssize_t nargs = PyTuple_GET_SIZE(args);
assert(nargs > 0);
mc->vectorcall_args = PyMem_Calloc(
nargs + (kwds ? PyDict_Size(kwds) : 0),
sizeof(PyObject*));
Expand Down Expand Up @@ -1594,14 +1595,6 @@ static int _methodcaller_initialize_vectorcall(methodcallerobject* mc)
return (void *)1;
}

static void _methodcaller_clear_vectorcall(methodcallerobject* mc)
{
if (mc->vectorcall_args != NULL) {
PyMem_Free(mc->vectorcall_args);
mc->vectorcall_args = 0;
}
Py_CLEAR(mc->vectorcall_kwnames);
}

static PyObject *
methodcaller_vectorcall(
Expand Down Expand Up @@ -1675,7 +1668,11 @@ methodcaller_clear(methodcallerobject *mc)
Py_CLEAR(mc->name);
Py_CLEAR(mc->xargs);
Py_CLEAR(mc->kwds);
_methodcaller_clear_vectorcall(mc);
if (mc->vectorcall_args != NULL) {
PyMem_Free(mc->vectorcall_args);
mc->vectorcall_args = 0;
}
Py_CLEAR(mc->vectorcall_kwnames);
}

static void
Expand Down