Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Micro-optimize _to_rgba_no_colorcycle. #30020

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 6, 2025

This patch speeds up conversions of #rgba-type formats by between 25% and 40% (while shortening the implementation), although real benefits should be limited because of caching in to_rgba.

PR summary

PR checklist

@tacaswell tacaswell added this to the v3.11.0 milestone May 6, 2025
@anntzer anntzer force-pushed the trnc branch 2 times, most recently from f3f2c44 to 9dc9749 Compare May 7, 2025 06:26
return (*[n / 0xff for n in bytes.fromhex(c[1:])],
alpha if alpha is not None else 1.)
elif len(c) == 4: # #rgb hex format, shorthand for #rrggbb.
return (*[int(n, 16) * 0x11 / 0xff for n in c[1:]],
Copy link
Member

Choose a reason for hiding this comment

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

This is just ?

Suggested change
return (*[int(n, 16) * 0x11 / 0xff for n in c[1:]],
return (*[int(n, 16) / 0xf for n in c[1:]],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah indeed, even better.

This patch speeds up conversions of `#rgba`-type formats by between 25%
and 40% (while shortening the implementation), although real benefits
should be limited because of caching in to_rgba.
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.

4 participants