There was an error while loading. Please reload this page.
1 parent 5f104d5 commit 6ff79f6Copy full SHA for 6ff79f6
2 files changed
Misc/NEWS.d/next/Core and Builtins/2020-03-15-23-16-00.bpo-37207.6XbnQA.rst
@@ -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
@@ -2014,6 +2014,28 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
2014
return set_update_internal(self, iterable);
2015
}
2016
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
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
2039
static PySequenceMethods set_as_sequence = {
2040
set_len, /* sq_length */
2041
0, /* sq_concat */
@@ -2162,6 +2184,7 @@ PyTypeObject PySet_Type = {
2162
2184
PyType_GenericAlloc, /* tp_alloc */
2163
2185
set_new, /* tp_new */
2164
2186
PyObject_GC_Del, /* tp_free */
2187
+ .tp_vectorcall = set_vectorcall,
2165
2188
};
2166
2189
2167
2190
/* frozenset object ********************************************************/
0 commit comments