Skip to content

Commit

Permalink
specialize zip: TrustedRandomAccess for Enumerate
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jun 14, 2016
1 parent 515c4d3 commit 13f8f40
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libcore/iter/mod.rs
Expand Up @@ -1092,6 +1092,15 @@ impl<I> DoubleEndedIterator for Enumerate<I> where
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Enumerate<I> where I: ExactSizeIterator {}

#[doc(hidden)]
unsafe impl<I> TrustedRandomAccess for Enumerate<I>
where I: TrustedRandomAccess
{
unsafe fn get_unchecked(&mut self, i: usize) -> (usize, I::Item) {
(self.count + i, self.iter.get_unchecked(i))
}
}

/// An iterator with a `peek()` that returns an optional reference to the next
/// element.
///
Expand Down

0 comments on commit 13f8f40

Please sign in to comment.