|
77 | 77 |
|
78 | 78 | #[inline] |
79 | 79 | fn size_hint(&self) -> (usize, Option<usize>) { |
80 | | - // for TRA: |
81 | | - //let size = cmp::min(self.a.size(), self.b.size()); |
82 | | - //(size, Some(size)) |
83 | | - |
84 | | - let (a_lower, a_upper) = self.a.size_hint(); |
85 | | - let (b_lower, b_upper) = self.b.size_hint(); |
86 | | - |
87 | | - let lower = cmp::min(a_lower, b_lower); |
88 | | - |
89 | | - let upper = match (a_upper, b_upper) { |
90 | | - (Some(x), Some(y)) => Some(cmp::min(x, y)), |
91 | | - (Some(x), None) => Some(x), |
92 | | - (None, Some(y)) => Some(y), |
93 | | - (None, None) => None, |
94 | | - }; |
95 | | - |
96 | | - (lower, upper) |
| 80 | + self.spec_size_hint() |
97 | 81 | } |
98 | 82 |
|
99 | 83 | fn fold<T, F>(self, init: T, f: F) -> T |
@@ -158,6 +142,7 @@ trait ZipSpec: Iterator { |
158 | 142 | F: FnMut(B, Self::Item) -> R, |
159 | 143 | R: Try<Output = B>; |
160 | 144 |
|
| 145 | + fn spec_size_hint(&self) -> (usize, Option<usize>); |
161 | 146 | } |
162 | 147 |
|
163 | 148 | impl<A, B> ZipSpec for Zip<A, B> |
@@ -189,6 +174,23 @@ where |
189 | 174 | } |
190 | 175 | try { accum } |
191 | 176 | } |
| 177 | + |
| 178 | + #[inline] |
| 179 | + default fn spec_size_hint(&self) -> (usize, Option<usize>) { |
| 180 | + let (a_lower, a_upper) = self.a.size_hint(); |
| 181 | + let (b_lower, b_upper) = self.b.size_hint(); |
| 182 | + |
| 183 | + let lower = cmp::min(a_lower, b_lower); |
| 184 | + |
| 185 | + let upper = match (a_upper, b_upper) { |
| 186 | + (Some(x), Some(y)) => Some(cmp::min(x, y)), |
| 187 | + (Some(x), None) => Some(x), |
| 188 | + (None, Some(y)) => Some(y), |
| 189 | + (None, None) => None, |
| 190 | + }; |
| 191 | + |
| 192 | + (lower, upper) |
| 193 | + } |
192 | 194 | } |
193 | 195 |
|
194 | 196 | impl<A, B> ZipSpec for Zip<A, B> |
@@ -233,6 +235,12 @@ where |
233 | 235 | self.cleanup(len, true); |
234 | 236 | try { accum } |
235 | 237 | } |
| 238 | + |
| 239 | + #[inline] |
| 240 | + fn spec_size_hint(&self) -> (usize, Option<usize>) { |
| 241 | + let size = cmp::min(self.a.size_hint().0, self.b.size_hint().0); |
| 242 | + (size, Some(size)) |
| 243 | + } |
236 | 244 | } |
237 | 245 |
|
238 | 246 | #[stable(feature = "rust1", since = "1.0.0")] |
|
0 commit comments