mirror of
https://github.com/python/cpython.git
synced 2025-10-22 14:42:22 +00:00
bpo-37207: Use PEP 590 vectorcall to speed up set() constructor (GH-19019)
This commit is contained in:
parent
5f104d56fa
commit
6ff79f6582
2 changed files with 25 additions and 0 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Speed up calls to ``set()`` by using the :pep:`590` ``vectorcall`` calling
|
||||||
|
convention. Patch by Dong-hee Na.
|
|
@ -2014,6 +2014,28 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
|
||||||
return set_update_internal(self, iterable);
|
return set_update_internal(self, iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
set_vectorcall(PyObject *type, PyObject * const*args,
|
||||||
|
size_t nargsf, PyObject *kwnames)
|
||||||
|
{
|
||||||
|
assert(PyType_Check(type));
|
||||||
|
|
||||||
|
if (!_PyArg_NoKwnames("set", kwnames)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
||||||
|
if (!_PyArg_CheckPositional("set", nargs, 0, 1)) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nargs) {
|
||||||
|
return make_new_set((PyTypeObject *)type, args[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return make_new_set((PyTypeObject *)type, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static PySequenceMethods set_as_sequence = {
|
static PySequenceMethods set_as_sequence = {
|
||||||
set_len, /* sq_length */
|
set_len, /* sq_length */
|
||||||
0, /* sq_concat */
|
0, /* sq_concat */
|
||||||
|
@ -2162,6 +2184,7 @@ PyTypeObject PySet_Type = {
|
||||||
PyType_GenericAlloc, /* tp_alloc */
|
PyType_GenericAlloc, /* tp_alloc */
|
||||||
set_new, /* tp_new */
|
set_new, /* tp_new */
|
||||||
PyObject_GC_Del, /* tp_free */
|
PyObject_GC_Del, /* tp_free */
|
||||||
|
.tp_vectorcall = set_vectorcall,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* frozenset object ********************************************************/
|
/* frozenset object ********************************************************/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue