Skip to content
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

GH-115685: Optimize TO_BOOL and variants based on truthiness of input. #116311

Merged
merged 4 commits into from
Mar 5, 2024

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Mar 4, 2024

Factors out the common logic for all TO_BOOL variants:

  • If the input is a bool, replace with a NOP
  • If the input is a "truthy" or "falsey" value, replace with a POP_TOP; LOAD_CONST True/False

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

LGTM. One minor formatting nit.

Python/optimizer_bytecodes.c Outdated Show resolved Hide resolved
Co-authored-by: Ken Jin <kenjin4096@gmail.com>
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

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

Nice.

@markshannon markshannon merged commit cbf3d38 into python:main Mar 5, 2024
50 checks passed
@markshannon markshannon deleted the optimize-on-truthiness branch March 5, 2024 11:23
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants