Repository navigation
bpo-37207: Use vertorcall for list() #18928
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
Changes from 4 commits
83f4943
c586da5
9d53274
0418c6b
84e88ca
d1fcdbe
47aba6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2717,6 +2717,35 @@ list___init___impl(PyListObject *self, PyObject *iterable) | |
| return 0; | ||
| } | ||
|
|
||
| static PyObject * | ||
| list_vectorcall(PyObject *type, PyObject * const*args, | ||
| size_t nargsf, PyObject *kwnames) | ||
| { | ||
| if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since #18980 is merged. if (!_PyArg_NoKwnames("list", kwnames)) {
return NULL;
} |
||
| PyErr_Format(PyExc_TypeError, "list() takes no keyword arguments"); | ||
| return NULL; | ||
| } | ||
| Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); | ||
| if (nargs > 1) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can replace it into if (!_PyArg_CheckPositional("list", nargs, 0, 1)) {
return NULL;
} |
||
| PyErr_Format(PyExc_TypeError, "list() expected at most 1 argument, got %zd", nargs); | ||
| return NULL; | ||
| } | ||
|
|
||
| assert(PyType_Check(type)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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__ | ||
|
|
||
|
|
@@ -3032,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 **************************/ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.