8000 bpo-37207: Use PEP 590 vectorcall to speed up set() by corona10 · Pull Request #19019 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37207: Use PEP 590 vectorcall to speed up set() #19019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2020
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 set()
  • Loading branch information
corona10 committed Mar 16, 2020
commit b6c7b1faae22eb5c32954e7ce800b9e56af3562c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Speed up calls to ``set()`` by using the :pep:`590` ``vectorcall`` calling
convention. Patch by Dong-hee Na.
24 changes: 24 additions & 0 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,29 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
return set_update_internal(self, iterable);
}

static PyObject*
set_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) {
PyErr_Format(PyExc_TypeError, "set() takes no keyword arguments");
return NULL;
}

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

assert(PyType_Check(type));

if (nargs) {
return make_new_set((PyTypeObject *)type, args[0]);
}

return make_new_set((PyTypeObject *)type, NULL);
}

static PySequenceMethods set_as_sequence = {
set_len, /* sq_length */
0, /* sq_concat */
Expand Down Expand Up @@ -2162,6 +2185,7 @@ PyTypeObject PySet_Type = {
PyType_GenericAlloc, /* tp_alloc */
set_new, /* tp_new */
PyObject_GC_Del, /* tp_free */< 4B59 /span>
.tp_vectorcall = set_vectorcall,
};

/* frozenset object ********************************************************/
Expand Down
0