-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Override Iterator methods when possible in std
#24214
Comments
I'd be happy to mentor work on this bug. |
I would be interested in working on this. |
Me too. |
Also interested in working on this. Anything left to do? |
@aturon Any word on this? |
Also, I'm curious if methods like |
@pnkfelix |
@Stebalien I think that is my point: You say "the underlying iterator can optimize |
Oh dear, I seem to've lost track of this thread, sorry to everyone who was waiting on me to organize things! I think probably the first place to start is just to get a list of the public iterators in std, which we can turn into a checklist and track assignees for. Part of the work will just be figuring out which cases are actually opportunities for doing better. Anyone interested in putting such a list together? I'd be glad to help coordinate. |
(And if no one is in a position to make a list, I can put one together tomorrow.) |
@pnkfelix It doesn't because:
So |
Here's core:
|
Thanks @Stebalien! I've added this as a checklist to the top of the issue. Anyone on thread: feel free to let me know if you want to take on a particular module/crate and I can put your name next to the item to "claim" it. |
I'm interested in this @aturon would I just fork the repo and work on master or should I make a separate branch like |
It usually works best to fork, and then create a branch in your local copy that tracks the master branch on this repo. We use the "fork and pull" model here. Once you get cooking, write a comment here to say which modules you're taking so we can avoid overlap. Thanks! |
I have one for I also have implementations for the iterator adapters but I'm getting an ICE on compile (code: https://github.com/Stebalien/rust/tree/iter)
Which I believe is: #24199 |
To add to the list, |
@Stebalien wrote:
I think I see. So you are saying Update: (seems obvious in hindsight. ah well.) |
@pnkfelix Exactly. It should also be possible to optimize methods like any, all, min, max, etc. by avoiding bounds checks but I don't know if it's worth it. However, it probably is worthwhile to optimize those methods for the Bytes/Chars iterators because doing so will allow us to read in large chunks instead of byte-by-byte. |
Note that in the long run, we'll need full "specialization" in order to optimize chained cases -- so this issue is primarily about the lowest-hanging fruit that we can tackle with today's trait system. |
Instead of using the O(n) defaults, define O(1) shortcuts. I also copied (and slightly modified) the relevant tests from the iter tests into the slice tests just in case someone comes along and changes them in the future. Partially implements #24214.
Additional iterators to consider optimizing:
|
Override methods `count`, `last`, and `nth` in vec::IntoIter. #24214
|
Just noticed |
Trivial implementation, as both are `ExactSizeIterator`s. Part of rust-lang#24214.
as a step from the appropriate state. Part of rust-lang#24214.
Implement `last` for `EscapeUnicode` The implementation is quite trivial as the last character is always `'{'`. As a side-effect it also improves the implementation of `last` for `EscapeUnicode`. Part of #24214, split from #31049. Maybe this (and the other changes that I will split from #31049) should wait for a test like `ed_iterator_specializations` to be added. Would it be sufficient to do the same for each possible escape length?
Trivial implementation, as both are `ExactSizeIterator`s. Part of rust-lang#24214.
…richton Implement `count` for `EscapeUnicode` and cleanup the code for `count` for `EscapeDefault` (instead of repeating the `match` for `size_hint` and `count`). This PR marks EscapeUnicode and EscapeDefault as ExactSizeIterator. The constraints for the trait implementations held even before this PR, but I am not sure if this is something we want to guarantee/expose (I would love feedback on this, especially on what would be the appropriate way to handle stabilisation, if needed). Part of rust-lang#24214, split from rust-lang#31049. The test for `count` was added in rust-lang#33103.
as a step from the appropriate state. Part of rust-lang#24214.
From comments it appears this is done. Thanks all. |
Now that
Iterator
has re-emerged as a single trait, it's possible to override default methods likecount
,last
andnth
for iterators on slices, vectors, and so on. We should audit the applicable iterators and take advantage of overrides when possible.libcore:
The text was updated successfully, but these errors were encountered: