about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrik Sverdrup <bluss@users.noreply.github.com>2016-04-21 21:35:39 +0200
committerUlrik Sverdrup <bluss@users.noreply.github.com>2016-06-14 15:51:49 +0200
commit13f8f40961d4e2166a80699a2e21a5dbf2211ecb (patch)
tree79923c08a4f66c0c8ec27737faa25ff42f16962b
parent515c4d3c1e6c38ff2d8bd3b3b3e5bd8b6b4c2322 (diff)
downloadrust-13f8f40961d4e2166a80699a2e21a5dbf2211ecb.tar.gz
rust-13f8f40961d4e2166a80699a2e21a5dbf2211ecb.zip
specialize zip: TrustedRandomAccess for Enumerate
-rw-r--r--src/libcore/iter/mod.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs
index 3ca37c40903..1a2d8e57e86 100644
--- a/src/libcore/iter/mod.rs
+++ b/src/libcore/iter/mod.rs
@@ -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.
 ///