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

Added size_hint impls for {PyDict,PyList,PySet,PyTuple}Iterators #1699

Merged
merged 1 commit into from
Jun 27, 2021

Conversation

ohadravid
Copy link
Contributor

Hi!

I've added size_hint impls for the iterators which can support it (while defaulting to 0 on Python-related errors).
Should make some_py_dict.iter().map(...).collect() faster by avoiding allocations!

@birkenfeld
Copy link
Member

I think this needs to take into account the current position of the iterator, since size_hint is supposed to return the remaining length, not the total length.

@davidhewitt
Copy link
Member

As well as the above, it would be awesome to add tests for these ☺️

@ohadravid ohadravid force-pushed the size_hints branch 2 times, most recently from d3c4036 to c613282 Compare June 27, 2021 10:56
@ohadravid
Copy link
Contributor Author

ohadravid commented Jun 27, 2021

@birkenfeld 🤦‍♂️ right! fixed.
@davidhewitt added the tests, and indeed PyTuple moves self.pos to len() + 1 in the end, so I got an ugly overflow.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks, this is great!

@davidhewitt davidhewitt merged commit 9249527 into PyO3:main Jun 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants