Skip to content

bpo-36781: Optimize sum() for bools.#13074

Merged
DinoV merged 4 commits intopython:masterfrom
serhiy-storchaka:sum-bool
Sep 10, 2019
Merged

bpo-36781: Optimize sum() for bools.#13074
DinoV merged 4 commits intopython:masterfrom
serhiy-storchaka:sum-bool

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
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
Comment thread Python/bltinmodule.c
continue;
}
if (PyLong_CheckExact(item)) {
if (PyLong_Check(item)) {
Copy link
Copy Markdown

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
Copy Markdown
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.

Comment thread Python/bltinmodule.c Outdated
@DinoV DinoV merged commit 88bdb92 into python:master Sep 10, 2019
@bedevere-bot
Copy link
Copy Markdown

@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