Skip to content

bpo-41870: Avoid the test when nargs=0 #22462

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 1 commit into from
Oct 1, 2020
Merged
Changes from all commits
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
6 changes: 3 additions & 3 deletions Objects/boolobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ bool_vectorcall(PyObject *type, PyObject * const*args,
assert(PyType_Check(type));
if (nargs) {
ok = PyObject_IsTrue(args[0]);
}
if (ok < 0) {
return NULL;
if (ok < 0) {
return NULL;
}
}
return PyBool_FromLong(ok);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume it won't make a difference because PyBool_FromLong will be likely smashed (inlined 😉 ) by the compiler, but can you check if there is any improvement in making the branch yourself here?

Basically changing the PyBool_FromLong(ok) to a conditional with Py_RETURN_TRUE and Py_RETURN_FALSE

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablogsal
I checked it locally and there was no improvement. :)
I will merge this PR without changing ;)

Thank you for the review!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pablogsal If you want to ensure that a function is inlined, I suggest to add a new variant of PyBool_FromLong() which is delcared as a static inline function.

}
Expand Down