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

Skip to content

Commit 6ff79f6

Browse files
authored
bpo-37207: Use PEP 590 vectorcall to speed up set() constructor (GH-19019)
1 parent 5f104d5 commit 6ff79f6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,28 @@ 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+
assert(PyType_Check(type));
2022+
2023+
if (!_PyArg_NoKwnames("set", kwnames)) {
2024+
return NULL;
2025+
}
2026+
2027+
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
2028+
if (!_PyArg_CheckPositional("set", nargs, 0, 1)) {
2029+
return NULL;
2030+
}
2031+
2032+
if (nargs) {
2033+
return make_new_set((PyTypeObject *)type, args[0]);
2034+
}
2035+
2036+
return make_new_set((PyTypeObject *)type, NULL);
2037+
}
2038+
2017< 827B /td>2039
static PySequenceMethods set_as_sequence = {
20182040
set_len, /* sq_length */
20192041
0, /* sq_concat */
@@ -2162,6 +2184,7 @@ PyTypeObject PySet_Type = {
21622184
PyType_GenericAlloc, /* tp_alloc */
21632185
set_new, /* tp_new */
21642186
PyObject_GC_Del, /* tp_free */
2187+
.tp_vectorcall = set_vectorcall,
21652188
};
21662189

21672190
/* frozenset object ********************************************************/

0 commit comments

Comments
 (0)
0