mirror of
https://github.com/python/cpython.git
synced 2025-09-27 10:50:04 +00:00
bpo-37233: optimize method_vectorcall in case of totalargs == 0 (GH-14550)
(cherry picked from commit 53c2143440
)
Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
This commit is contained in:
parent
c7570d402e
commit
1099e343e8
1 changed files with 10 additions and 6 deletions
|
@ -62,9 +62,13 @@ method_vectorcall(PyObject *method, PyObject *const *args,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
||||||
PyObject **newargs;
|
|
||||||
Py_ssize_t totalargs = nargs + nkwargs;
|
Py_ssize_t totalargs = nargs + nkwargs;
|
||||||
|
if (totalargs == 0) {
|
||||||
|
return _PyObject_Vectorcall(func, &self, 1, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
|
PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
|
||||||
|
PyObject **newargs;
|
||||||
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
|
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
|
||||||
newargs = newargs_stack;
|
newargs = newargs_stack;
|
||||||
}
|
}
|
||||||
|
@ -77,11 +81,11 @@ method_vectorcall(PyObject *method, PyObject *const *args,
|
||||||
}
|
}
|
||||||
/* use borrowed references */
|
/* use borrowed references */
|
||||||
newargs[0] = self;
|
newargs[0] = self;
|
||||||
if (totalargs) { /* bpo-37138: if totalargs == 0, then args may be
|
/* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
|
||||||
* NULL and calling memcpy() with a NULL pointer
|
* We need this, since calling memcpy() with a NULL pointer is
|
||||||
* is undefined behaviour. */
|
* undefined behaviour. */
|
||||||
|
assert(args != NULL);
|
||||||
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
|
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
|
||||||
}
|
|
||||||
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
|
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
|
||||||
if (newargs != newargs_stack) {
|
if (newargs != newargs_stack) {
|
||||||
PyMem_Free(newargs);
|
PyMem_Free(newargs);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue