8000 bpo-37207: Use vectorcall for list() (GH-18928) · python/cpython@ce10554 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce10554

Browse files
encukoumarkshannoncorona10
authored
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>
1 parent 614f172 commit ce10554

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed up calls to ``list()`` by using the :pep:`590` ``vectorcall``
2+
calling convention. Patch by Mark Shannon.

Objects/listobject.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,33 @@ list___init___impl(PyListObject *self, PyObject *iterable)
27192719
return 0;
27202720
}
27212721

2722+
static PyObject *
2723+
list_vectorcall(PyObject *type, PyObject * const*args,
2724+
size_t nargsf, PyObject *kwnames)
2725+
{
2726+
if (!_PyArg_NoKwnames("list", kwnames)) {
2727+
return NULL;
2728+
}
2729+
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
2730+
if (!_PyArg_CheckPositional("list", nargs, 0, 1)) {
2731+
return NULL;
2732+
}
2733+
2734+
assert(PyType_Check(type));
2735+
PyObject *list = PyType_GenericAlloc((PyTypeObject *)type, 0);
2736+
if (list == NULL) {
2737+
return NULL;
2738+
}
2739+
if (nargs) {
2740+
if (list___init___impl((PyListObject *)list, args[0])) {
2741+
Py_DECREF(list);
2742+
return NULL;
2743+
}
2744+
}
2745+
return list;
2746+
}
2747+
2748+
27222749
/*[clinic input]
27232750
list.__sizeof__
27242751
@@ -3034,6 +3061,7 @@ PyTypeObject PyList_Type = {
30343061
PyType_GenericAlloc, /* tp_alloc */
30353062
PyType_GenericNew, /* tp_new */
30363063
PyObject_GC_Del, /* tp_free */
3064+
.tp_vectorcall = list_vectorcall,
30373065
};
30383066

30393067
/*********************** List Iterator **************************/

0 commit comments

Comments
 (0)
0