bpo-37207: Use vectorcall for list() (GH-18928)

Speed up calls to list() by using the PEP 590 vectorcall
calling convention. Patch by Mark Shannon.

Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
This commit is contained in:
Petr Viktorin 2020-03-30 14:16:16 +02:00 committed by GitHub
parent 614f17211c
commit ce105541f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1,2 @@
Speed up calls to ``list()`` by using the :pep:`590` ``vectorcall``
calling convention. Patch by Mark Shannon.

View File

@ -2719,6 +2719,33 @@ list___init___impl(PyListObject *self, PyObject *iterable)
return 0;
}
static PyObject *
list_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
if (!_PyArg_NoKwnames("list", kwnames)) {
return NULL;
}
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("list", nargs, 0, 1)) {
return NULL;
}
assert(PyType_Check(type));
PyObject *list = PyType_GenericAlloc((PyTypeObject *)type, 0);
if (list == NULL) {
return NULL;
}
if (nargs) {
if (list___init___impl((PyListObject *)list, args[0])) {
Py_DECREF(list);
return NULL;
}
}
return list;
}
/*[clinic input]
list.__sizeof__
@ -3034,6 +3061,7 @@ PyTypeObject PyList_Type = {
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = list_vectorcall,
};
/*********************** List Iterator **************************/