Skip to content

Commit

Permalink
Rollup merge of rust-lang#52193 - Emerentius:step_by_note, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

step_by: leave time of item skip unspecified

This gives us some leeway when optimizing. `StepBy<RangeFrom<_>>` is one case where this is needed.
  • Loading branch information
Mark-Simulacrum authored Jul 11, 2018
2 parents 322632a + 39fcfa8 commit 74cc821
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,30 @@ pub trait Iterator {
/// Creates an iterator starting at the same point, but stepping by
/// the given amount at each iteration.
///
/// Note that it will always return the first element of the iterator,
/// Note 1: The first element of the iterator will always be returned,
/// regardless of the step given.
///
/// Note 2: The time at which ignored elements are pulled is not fixed.
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
/// but is also free to behave like the sequence
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
/// Which way is used may change for some iterators for performance reasons.
/// The second way will advance the iterator earlier and may consume more items.
///
/// `advance_n_and_return_first` is the equivalent of:
/// ```
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
/// where
/// I: Iterator,
/// {
/// let next = iter.next();
/// if total_step > 1 {
/// iter.nth(total_step-2);
/// }
/// next
/// }
/// ```
///
/// # Panics
///
/// The method will panic if the given step is `0`.
Expand Down

0 comments on commit 74cc821

Please sign in to comment.