Visitar URL original
bpo-34838: Perform a more easily branch-predictable type check by ammaraskar · Pull Request #9659 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223141346/https://github.com/python/cpython/pull/9659
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

bpo-34838: Perform a more easily branch-predictable type check #9659

Merged
merged 1 commit into from Jan 12, 2019

Conversation

ammaraskar
Copy link
Member

@ammaraskar ammaraskar commented Oct 1, 2018 •

More details available on the bpo page.

https://bugs.python.org/issue34838

if self.subclass_of == '&PyTuple_Type':
err_check = '!PyTuple_Check({})'.format(self.name)
elif self.subclass_of == '&PyDict_Type':
err_check = '!PyDict_Check({})'.format(self.name)
Copy link
Contributor

@MojoVampire MojoVampire Oct 3, 2018

Choose a reason for hiding this comment

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

Why only tuple and dict? Same fast path would apply to all types with fast subclass flags from object.h (

/* These flags are used to determine if a type is a subclass. */
), including int, list, bytes, str, BaseException and type.

Copy link
Contributor

@MojoVampire MojoVampire Oct 3, 2018 •

Choose a reason for hiding this comment

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

Admittedly, most things that accept int should probably accept anything convertable to int via __index__ even if it's not a direct subclass, but otherwise it seems like all the others should have the optimization available.

Argument clinic now generates fast inline code for
positional parsing, so the manually implemented type
check in math.dist can be removed.
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.

None yet

6 participants