You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Override Iterator methods when possible in std #24214
Now that Iterator has re-emerged as a single trait, it's possible to override default methods like count, last and nth for iterators on slices, vectors, and so on. We should audit the applicable iterators and take advantage of overrides when possible.
Also, I'm curious if methods like skip(n) are required to actually call next n tines, or if they are allowed to "jump ahead" on random-access iterators. (Maybe that sort of trick will have to wait for specialization in the language, to avoid composing that with e.g. a map or other potentially side-effectful iterator
@Stebalien I think that is my point: You say "the underlying iterator can optimize nth if possible", but I claim to allow that would require changing the specification of nth, which currently is specified as "going through n iterations", which I interpret as "calls the next() method n times" -- a side-effectful iterator chain (e.g. one using inspect) can observe the difference between that or jumping ahead n steps when given a random-access iterator.
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.
Skip can assume that the underlying iterator correctly implements nth.
Some iterators (e.g. slice::Iter) have side-effect-free next methods. These iterators can implement optimized nth functions.
So vec![1, 2, 3, 4, 5].iter().skip(2) can have a constant time skip given an optimized slice::Iter::nth method. Unfortunately, as implemented, ranges can't optimize nth this way because they are generic.
Activity
aturon commentedon Apr 8, 2015
I'd be happy to mentor work on this bug.
djmally commentedon Apr 9, 2015
I would be interested in working on this.
GuillaumeGomez commentedon Apr 9, 2015
Me too.
tamird commentedon Apr 17, 2015
Also interested in working on this. Anything left to do?
djmally commentedon Apr 20, 2015
@aturon Any word on this?
pnkfelix commentedon Apr 20, 2015
Also, I'm curious if methods like
skip(n)are required to actually callnextn tines, or if they are allowed to "jump ahead" on random-access iterators. (Maybe that sort of trick will have to wait for specialization in the language, to avoid composing that with e.g. amapor other potentially side-effectful iteratorStebalien commentedon Apr 21, 2015
@pnkfelix
skipcan callnthon the underlying iterator and the underlying iterator can optimizenthif possible.pnkfelix commentedon Apr 21, 2015
@Stebalien I think that is my point: You say "the underlying iterator can optimize
nthif possible", but I claim to allow that would require changing the specification ofnth, which currently is specified as "going throughniterations", which I interpret as "calls thenext()methodntimes" -- a side-effectful iterator chain (e.g. one usinginspect) can observe the difference between that or jumping aheadnsteps when given a random-access iterator.aturon commentedon Apr 21, 2015
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.
aturon commentedon Apr 21, 2015
(And if no one is in a position to make a list, I can put one together tomorrow.)
Stebalien commentedon Apr 21, 2015
@pnkfelix It doesn't because:
nth.slice::Iter) have side-effect-freenextmethods. These iterators can implement optimizednthfunctions.So
vec![1, 2, 3, 4, 5].iter().skip(2)can have a constant time skip given an optimizedslice::Iter::nthmethod. Unfortunately, as implemented, ranges can't optimizenththis way because they are generic.37 remaining items
Implement `EscapeUnicode::nth`
Implement `last` for `EscapeUnicode`
Auto merge of #33103 - ranma42:escape-unicode-last, r=alexcrichton
Implement `EscapeUnicode::nth`
brson commentedon Jun 27, 2016
From comments it appears this is done. Thanks all.