core, collections: Implement better .is_empty() for slice and vec iterators

These iterators can use a pointer comparison instead of computing the length.
This commit is contained in:
Ulrik Sverdrup
2016-11-22 23:31:31 +01:00
parent 5a3aa2f73c
commit 74cde120e5
5 changed files with 32 additions and 4 deletions

View File

@@ -983,7 +983,11 @@ impl<'a, T> Iter<'a, T> {
iterator!{struct Iter -> *const T, &'a T}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for Iter<'a, T> {}
impl<'a, T> ExactSizeIterator for Iter<'a, T> {
fn is_empty(&self) -> bool {
self.ptr == self.end
}
}
#[unstable(feature = "fused", issue = "35602")]
impl<'a, T> FusedIterator for Iter<'a, T> {}
@@ -1107,7 +1111,11 @@ impl<'a, T> IterMut<'a, T> {
iterator!{struct IterMut -> *mut T, &'a mut T}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {}
impl<'a, T> ExactSizeIterator for IterMut<'a, T> {
fn is_empty(&self) -> bool {
self.ptr == self.end
}
}
#[unstable(feature = "fused", issue = "35602")]
impl<'a, T> FusedIterator for IterMut<'a, T> {}