Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-37207: Use vertorcall for list() #18928

Merged
merged 7 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up calls to ``list()`` by using the :pep:`590` ``vectorcall``
calling convention. Patch by Mark Shannon.
28 changes: 28 additions & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2717,6 +2717,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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this assert into the top of the function body since this parameter is the 1st parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why that's necessary.

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__

Expand Down Expand Up @@ -3032,6 +3059,7 @@ PyTypeObject PyList_Type = {
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = list_vectorcall,
};

/*********************** List Iterator **************************/
Expand Down