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

Skip to content

bpo-41870: Use PEP 590 vectorcall to speed up bool() #22427

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
Sep 28, 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
Next Next commit
bpo-41870: Use PEP 590 vectorcall to speed up bool()
  • Loading branch information
corona10 committed Sep 27, 2020
commit d587d554d7e6dce602d3ebfc3ef7ab2398842249
25 changes: 25 additions & 0 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ bool_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return PyBool_FromLong(ok);
}

static PyObject *
bool_vectorcall(PyObject *type, PyObject * const*args,
size_t nargsf, PyObject *kwnames)
{
long ok = 0;
if (!_PyArg_NoKwnames("bool", kwnames)) {
return NULL;
}

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

assert(PyType_Check(type));
if (nargs) {
ok = PyObject_IsTrue(args[0]);
}
if (ok < 0) {
return NULL;
}
return PyBool_FromLong(ok);
}

/* Arithmetic operations redefined to return bool if both args are bool. */

static PyObject *
Expand Down Expand Up @@ -170,6 +194,7 @@ PyTypeObject PyBool_Type = {
0, /* tp_init */
0, /* tp_alloc */
bool_new, /* tp_new */
.tp_vectorcall = bool_vectorcall,
};

/* The objects representing bool values False and True */
Expand Down
0