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

Skip to content

bpo-37207: Use PEP 590 vectorcall to speed up frozenset() #19053

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 7 commits into from
Mar 18, 2020
Merged
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
Prev Previous commit
Next Next commit
bpo-37207: Apply Victor's review
  • Loading branch information
corona10 committed Mar 18, 2020
commit b3748fb9c4021ad57a11d597e20fb640bc4c581d
68 changes: 35 additions & 33 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1063,36 +1063,51 @@ make_new_set_basetype(PyTypeObject *type, PyObject *iterable)
/* The empty frozenset is a singleton */
static PyObject *emptyfrozenset = NULL;

static PyObject *
make_new_frozenset(PyTypeObject *type, PyObject *iterable)
{
if (iterable != NULL) {
/* frozenset(f) is idempotent */
if (PyFrozenSet_CheckExact(iterable)) {
Py_INCREF(iterable);
return iterable;
}
PyObject *res = make_new_set((PyTypeObject *)type, iterable);
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 *
frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyObject *iterable = NULL, *result;
PyObject *iterable = NULL;

if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset", kwds))
if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset", kwds)) {
return NULL;
}

if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) {
return NULL;
}

if (type != &PyFrozenSet_Type)
if (type != &PyFrozenSet_Type) {
return make_new_set(type, iterable);
}

if (iterable != NULL) {
/* frozenset(f) is idempotent */
if (PyFrozenSet_CheckExact(iterable)) {
Py_INCREF(iterable);
return iterable;
}
result = make_new_set(type, iterable);
if (result == NULL || PySet_GET_SIZE(result))
return result;
Py_DECREF(result);
return make_new_frozenset(type, iterable);
}
/* The empty frozenset is a singleton */
if (emptyfrozenset == NULL)
emptyfrozenset = make_new_set(type, NULL);
Py_XINCREF(emptyfrozenset);
return emptyfrozenset;
return make_new_frozenset(type, NULL);
}

static PyObject *
Expand All @@ -1111,23 +1126,10 @@ frozenset_vectorcall(PyObject *type, PyObject * const*args,
}

if (nargs) {
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);
return make_new_frozenset((PyTypeObject *)type, args[0]);
}

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

static PyObject *
Expand Down
0