Skip to content

Commit

Permalink
Added comments.
Browse files Browse the repository at this point in the history
Removed unnecessarry empty impls.
Moved code to organise it better
  • Loading branch information
rakshith-ravi committed Apr 10, 2020
1 parent 0a54a94 commit 51cd29c
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/libcore/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ macro_rules! fuse {
};
}

// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`.
// Implementing this as a directly-expanded macro helps codegen performance.
macro_rules! unchecked {
($self:ident) => {
match $self {
Fuse { iter: Some(iter) } => iter,
// SAFETY: the specialized iterator never sets `None`
Fuse { iter: None } => unsafe { intrinsics::unreachable() },
}
};
}

// Any implementation here is made internal to avoid exposing default fns outside this trait
#[stable(feature = "rust1", since = "1.0.0")]
impl<I> Iterator for Fuse<I>
where
Expand Down Expand Up @@ -159,27 +172,6 @@ where
}
}

// NOTE: for `I: FusedIterator`, we assume that the iterator is always `Some`.
// Implementing this as a directly-expanded macro helps codegen performance.
macro_rules! unchecked {
($self:ident) => {
match $self {
Fuse { iter: Some(iter) } => iter,
// SAFETY: the specialized iterator never sets `None`
Fuse { iter: None } => unsafe { intrinsics::unreachable() },
}
};
}

#[stable(feature = "fused", since = "1.26.0")]
impl<I> Iterator for Fuse<I> where I: FusedIterator {}

#[stable(feature = "fused", since = "1.26.0")]
impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator + FusedIterator {}

#[stable(feature = "rust1", since = "1.0.0")]
impl<I> ExactSizeIterator for Fuse<I> where I: ExactSizeIterator + FusedIterator {}

unsafe impl<I> TrustedRandomAccess for Fuse<I>
where
I: TrustedRandomAccess,
Expand All @@ -198,6 +190,9 @@ where
}

// Fuse specialization trait
// Iterators and DoubleEndedIterators cannot be overlapped successfully
// So, they're separated into each it's own trait to provide internal implementations
// Similarly, ExactSizeIterators cannot be overlapped, so requires its own trait
#[doc(hidden)]
trait FuseIteratorImpl<I> {
type Item;
Expand Down

0 comments on commit 51cd29c

Please sign in to comment.