diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-11-22 23:31:31 +0100 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2016-11-23 02:31:41 +0100 |
| commit | 74cde120e5edb8d62fb63e8ab738ba0c67ec4d5c (patch) | |
| tree | 9917a6fe6390c3c68aceac5f9f8ffbff245c53ea /src/libcore/slice.rs | |
| parent | 5a3aa2f73cbb08c6e41418c5378791fa24a66146 (diff) | |
| download | rust-74cde120e5edb8d62fb63e8ab738ba0c67ec4d5c.tar.gz rust-74cde120e5edb8d62fb63e8ab738ba0c67ec4d5c.zip | |
core, collections: Implement better .is_empty() for slice and vec iterators
These iterators can use a pointer comparison instead of computing the length.
Diffstat (limited to 'src/libcore/slice.rs')
| -rw-r--r-- | src/libcore/slice.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 871b63145ca..ede45111ebb 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -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> {} |
