bpo-41922: Use PEP 590 vectorcall to speed up reversed() (GH-22523)

This commit is contained in:
Dong-hee Na 2020-10-04 02:16:56 +09:00 committed by GitHub
parent 3fe6148937
commit d646e91f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,2 @@
Speed up calls to ``reversed()`` by using the :pep:`590` ``vectorcall``
calling convention. Patch by Dong-hee Na.

View File

@ -314,6 +314,24 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq)
return (PyObject *)ro; return (PyObject *)ro;
} }
static PyObject *
reversed_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
assert(PyType_Check(type));
if (!_PyArg_NoKwnames("reversed", kwnames)) {
return NULL;
}
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("reversed", nargs, 1, 1)) {
return NULL;
}
return reversed_new_impl((PyTypeObject *)type, args[0]);
}
static void static void
reversed_dealloc(reversedobject *ro) reversed_dealloc(reversedobject *ro)
{ {
@ -445,4 +463,5 @@ PyTypeObject PyReversed_Type = {
PyType_GenericAlloc, /* tp_alloc */ PyType_GenericAlloc, /* tp_alloc */
reversed_new, /* tp_new */ reversed_new, /* tp_new */
PyObject_GC_Del, /* tp_free */ PyObject_GC_Del, /* tp_free */
.tp_vectorcall = (vectorcallfunc)reversed_vectorcall,
}; };