From ba1a6f3b5181944d40d55e633c106ab0e2394490 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 31 Dec 2018 22:52:08 -0500 Subject: [PATCH 1/4] Add Rev delegate methods for the impl of Iterator. --- src/libcore/iter/mod.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 03369d6c8f3fd..27df24301ef1c 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -418,32 +418,45 @@ impl Iterator for Rev where I: DoubleEndedIterator { fn next(&mut self) -> Option<::Item> { self.iter.next_back() } #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } + #[inline] + fn count(self) -> usize { self.iter.count() } + #[inline] + fn last(mut self) -> Option<::Item> { self.iter.next() } #[inline] fn nth(&mut self, n: usize) -> Option<::Item> { self.iter.nth_back(n) } + #[inline] fn try_fold(&mut self, init: B, f: F) -> R where - Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try + Self: Sized, F: FnMut(B, ::Item) -> R, R: Try { self.iter.try_rfold(init, f) } + #[inline] fn fold(self, init: Acc, f: F) -> Acc - where F: FnMut(Acc, Self::Item) -> Acc, + where F: FnMut(Acc, ::Item) -> Acc, { self.iter.rfold(init, f) } #[inline] - fn find

(&mut self, predicate: P) -> Option - where P: FnMut(&Self::Item) -> bool + fn find

(&mut self, predicate: P) -> Option<::Item> + where P: FnMut(&::Item) -> bool { self.iter.rfind(predicate) } + #[inline] + fn position

(&mut self, predicate: P) -> Option where + P: FnMut(::Item) -> bool + { + self.iter.rposition(predicate) + } + #[inline] fn rposition

(&mut self, predicate: P) -> Option where - P: FnMut(Self::Item) -> bool + P: FnMut(::Item) -> bool { self.iter.position(predicate) } From c779782c6b3c66ec2f819105f655d210a1142d16 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 31 Dec 2018 23:28:20 -0500 Subject: [PATCH 2/4] Add inline to a few more methods --- src/libcore/iter/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 27df24301ef1c..20b3b31ed43a5 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -470,18 +470,21 @@ impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { #[inline] fn nth_back(&mut self, n: usize) -> Option<::Item> { self.iter.nth(n) } + #[inline] fn try_rfold(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try { self.iter.try_fold(init, f) } + #[inline] fn rfold(self, init: Acc, f: F) -> Acc where F: FnMut(Acc, Self::Item) -> Acc, { self.iter.fold(init, f) } + #[inline] fn rfind

(&mut self, predicate: P) -> Option where P: FnMut(&Self::Item) -> bool { @@ -493,10 +496,12 @@ impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { impl ExactSizeIterator for Rev where I: ExactSizeIterator + DoubleEndedIterator { + #[inline] fn len(&self) -> usize { self.iter.len() } + #[inline] fn is_empty(&self) -> bool { self.iter.is_empty() } From d752f81ac9bceb0519f18701ee8c17642922b8f9 Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 31 Dec 2018 23:38:45 -0500 Subject: [PATCH 3/4] Remove `position` --- src/libcore/iter/mod.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index 20b3b31ed43a5..a1191c768c345 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -447,13 +447,6 @@ impl Iterator for Rev where I: DoubleEndedIterator { self.iter.rfind(predicate) } - #[inline] - fn position

(&mut self, predicate: P) -> Option where - P: FnMut(::Item) -> bool - { - self.iter.rposition(predicate) - } - #[inline] fn rposition

(&mut self, predicate: P) -> Option where P: FnMut(::Item) -> bool From e78581ae2662819988ed0709b92b9b2c88a5852e Mon Sep 17 00:00:00 2001 From: Czipperz Date: Mon, 31 Dec 2018 23:52:07 -0500 Subject: [PATCH 4/4] Change Item types to `Self::Item` instead of `::Item` --- src/libcore/iter/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index a1191c768c345..33e7e919d5870 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -415,41 +415,41 @@ impl Iterator for Rev where I: DoubleEndedIterator { type Item = ::Item; #[inline] - fn next(&mut self) -> Option<::Item> { self.iter.next_back() } + fn next(&mut self) -> Option { self.iter.next_back() } #[inline] fn size_hint(&self) -> (usize, Option) { self.iter.size_hint() } #[inline] fn count(self) -> usize { self.iter.count() } #[inline] - fn last(mut self) -> Option<::Item> { self.iter.next() } + fn last(mut self) -> Option { self.iter.next() } #[inline] - fn nth(&mut self, n: usize) -> Option<::Item> { self.iter.nth_back(n) } + fn nth(&mut self, n: usize) -> Option { self.iter.nth_back(n) } #[inline] fn try_fold(&mut self, init: B, f: F) -> R where - Self: Sized, F: FnMut(B, ::Item) -> R, R: Try + Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try { self.iter.try_rfold(init, f) } #[inline] fn fold(self, init: Acc, f: F) -> Acc - where F: FnMut(Acc, ::Item) -> Acc, + where F: FnMut(Acc, Self::Item) -> Acc, { self.iter.rfold(init, f) } #[inline] - fn find

(&mut self, predicate: P) -> Option<::Item> - where P: FnMut(&::Item) -> bool + fn find

(&mut self, predicate: P) -> Option + where P: FnMut(&Self::Item) -> bool { self.iter.rfind(predicate) } #[inline] fn rposition

(&mut self, predicate: P) -> Option where - P: FnMut(::Item) -> bool + P: FnMut(Self::Item) -> bool { self.iter.position(predicate) } @@ -458,10 +458,10 @@ impl Iterator for Rev where I: DoubleEndedIterator { #[stable(feature = "rust1", since = "1.0.0")] impl DoubleEndedIterator for Rev where I: DoubleEndedIterator { #[inline] - fn next_back(&mut self) -> Option<::Item> { self.iter.next() } + fn next_back(&mut self) -> Option { self.iter.next() } #[inline] - fn nth_back(&mut self, n: usize) -> Option<::Item> { self.iter.nth(n) } + fn nth_back(&mut self, n: usize) -> Option { self.iter.nth(n) } #[inline] fn try_rfold(&mut self, init: B, f: F) -> R where