Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-37207: Use PEP 590 vectorcall to speed up frozenset()
  • Loading branch information
corona10 committed Mar 18, 2020
commit d467294bbad29d9d6b615a7e72758ffb5c96dbe1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up calls to ``frozenset()`` by using the :pep:`590` ``vectorcall``
calling convention. Patch by Dong-hee Na.
36 changes: 36 additions & 0 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,41 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return emptyfrozenset;
}

static PyObject *
frozenset_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
assert(PyType_Check(type));
Comment thread
corona10 marked this conversation as resolved.
Outdated

if (!_PyArg_NoKwnames("frozenset", kwnames)) {
return NULL;
}

Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
if (!_PyArg_CheckPositional("frozenset", nargs, 0, 1)) {
return NULL;
}

if (nargs) {
Comment thread
corona10 marked this conversation as resolved.
Outdated
if (PyFrozenSet_CheckExact(args[0])) {
Py_INCREF(args[0]);
return args[0];
}
PyObject *res = make_new_set((PyTypeObject *)type, args[0]);
if (res == NULL || PySet_GET_SIZE(res)) {
return res;
}
Py_DECREF(res);
}

// The empty frozenset is a singleton
if (emptyfrozenset == NULL) {
emptyfrozenset = make_new_set((PyTypeObject *)type, NULL);
}
Py_XINCREF(emptyfrozenset);
return emptyfrozenset;
}

static PyObject *
set_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
Expand Down Expand Up @@ -2283,6 +2318,7 @@ PyTypeObject PyFrozenSet_Type = {
PyType_GenericAlloc, /* tp_alloc */
frozenset_new, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = frozenset_vectorcall,
};


Expand Down