Hello,
I have questions regarding the std's implementation of "advancing" the iterators: slice::Iter(Mut)
, iter::{Once, Repeat, Empty, FromFn}
.
Looking at slice::Iter
' Iterator::nth
implementation you can see it does pointer arithmetics (post_inc_start) instead of looping, which is great. But it keeps the default advance_by
(which is used by the default nth
btw). Why?
For the "special" iterator in the iter
module we do not get this optimization, we get the default looping behavior:
-
Once
/Empty
: I guess it is optimized away by the compiler here -
Repeat
/FromFn
: are there used cases where we want to clone unused elements?
Just wondering why not writing the simple, obvious overrides.
Thanks!