Skip to content

Commit

Permalink
specialize zip: Implement TrustedRandomAccess for slice iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Jun 14, 2016
1 parent f8d2fdf commit 592eaa5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/libcore/slice.rs
Expand Up @@ -50,6 +50,7 @@ use result::Result::{Ok, Err};
use ptr;
use mem;
use marker::{Copy, Send, Sync, self};
use iter_private::TrustedRandomAccess;

#[repr(C)]
struct Repr<T> {
Expand Down Expand Up @@ -1942,3 +1943,17 @@ macro_rules! impl_marker_for {

impl_marker_for!(BytewiseEquality,
u8 i8 u16 i16 u32 i32 u64 i64 usize isize char bool);

#[doc(hidden)]
unsafe impl<'a, T> TrustedRandomAccess for Iter<'a, T> {
unsafe fn get_unchecked(&mut self, i: usize) -> &'a T {
&*self.ptr.offset(i as isize)
}
}

#[doc(hidden)]
unsafe impl<'a, T> TrustedRandomAccess for IterMut<'a, T> {
unsafe fn get_unchecked(&mut self, i: usize) -> &'a mut T {
&mut *self.ptr.offset(i as isize)
}
}

0 comments on commit 592eaa5

Please sign in to comment.