summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2020-03-30 12:16:16 (GMT)
committerGitHub <noreply@github.com>2020-03-30 12:16:16 (GMT)
commitce105541f8ebcf2dffcadedfdeffdb698a0edb44 (patch)
treecfd0b480978c62f814d56fefc8e397658b168641 /Objects/listobject.c
parent614f17211c5fc0e5b828be1d3320661d1038fe8f (diff)
downloadcpython-ce105541f8ebcf2dffcadedfdeffdb698a0edb44.zip
cpython-ce105541f8ebcf2dffcadedfdeffdb698a0edb44.tar.gz
cpython-ce105541f8ebcf2dffcadedfdeffdb698a0edb44.tar.bz2
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>
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 4e2b6a9..91687bc 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -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 **************************/