Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented May 3, 2019

@serhiy-storchaka serhiy-storchaka changed the title Optimize sum() for bools. bpo-36781: Optimize sum() for bools. May 5, 2019
continue;
}
if (PyLong_CheckExact(item)) {
if (PyLong_Check(item)) {
Copy link

Choose a reason for hiding this comment

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

Why is this not PyLong_CheckExact(item) || PyBool_Check(item) like the one above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because why not? This extends the optimization to other int subclasses.

There is a reason why PyLong_Check(item) is not used above: because __radd__ method in the int subclass takes precedence. But for float+int it is not used.

@DinoV DinoV merged commit 88bdb92 into python:master Sep 10, 2019
@bedevere-bot
Copy link

@DinoV: Please replace # with GH- in the commit message next time. Thanks!

websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
* Optimize sum() for bools.

* Fix sum([], False).

* Add a NEWS entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants