8000 bpo-37207: Use PEP 590 vectorcall to speed up set() · python/cpython@b6c7b1f · GitHub
[go: up one dir, main page]

Skip to content

Commit b6c7b1f

Browse files
committed
bpo-37207: Use PEP 590 vectorcall to speed up set()
1 parent 87ec86c commit b6c7b1f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-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 ``set()`` by using the :pep:`590` ``vectorcall`` calling
2+
convention. Patch by Dong-hee Na.

Objects/setobject.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,29 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
20142014
return set_update_internal(self, iterable);
20152015
}
20162016

2017+
static PyObject*
2018+
set_vectorcall(PyObject *type, PyObject * const*args,
2019+
size_t nargsf, PyObject *kwnames)
2020+
{
2021+
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) {
2022+
PyErr_Format(PyExc_TypeError, "set() takes no keyword arguments");
2023+
return NULL;
2024+
}
2025+
2026+
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
2027+
if (!_PyArg_CheckPositional("set", nargs, 0, 1)) {
2028+
return NULL;
2029+
}
2030+
2031+
assert(PyType_Check(type));
2032+
2033+
if (nargs) {
2034+
return make_new_set((PyTypeObject *)type, args[0]);
2035+
}
2036+
2037+
return make_new_set((PyTypeObject *)type, NULL);
2038+
}
2039+
20172040
static PySequenceMethods set_as_sequence = {
20182041
set_len, /* sq_length */
20192042
0, /* sq_concat */
@@ -2162,6 +2185,7 @@ PyTypeObject PySet_Type = {
21622185
PyType_GenericAlloc, /* tp_alloc */
21632186
set_new, /* tp_new */
21642187
PyObject_GC_Del, /* tp_free */
2188+
.tp_vectorcall = set_vectorcall,
21652189
};
21662190

21672191
/* frozenset object ********************************************************/

0 commit comments

Comments
 (0)
0