@@ -65,7 +65,7 @@ use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
65
65
use cmp;
66
66
use iterator:: * ;
67
67
use libc:: c_void;
68
- use num:: Zero ;
68
+ use num:: { Integer , Zero , CheckedAdd , Saturating } ;
69
69
use option:: { None , Option , Some } ;
70
70
use ptr:: to_unsafe_ptr;
71
71
use ptr;
@@ -209,6 +209,7 @@ pub struct SplitIterator<'self, T> {
209
209
}
210
210
211
211
impl < ' self , T > Iterator < & ' self [ T ] > for SplitIterator < ' self , T > {
212
+ #[ inline]
212
213
fn next ( & mut self ) -> Option < & ' self [ T ] > {
213
214
if self . finished { return None ; }
214
215
@@ -230,6 +231,21 @@ impl<'self, T> Iterator<&'self [T]> for SplitIterator<'self, T> {
230
231
}
231
232
}
232
233
}
234
+
235
+ #[ inline]
236
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
237
+ if self . finished {
238
+ return ( 0 , Some ( 0 ) )
239
+ }
240
+ // if the predicate doesn't match anything, we yield one slice
241
+ // if it matches every element, we yield N+1 empty slices where
242
+ // N is either the number of elements or the number of splits.
243
+ match ( self . v . len ( ) , self . n ) {
244
+ ( 0 , _) => ( 1 , Some ( 1 ) ) ,
245
+ ( _, 0 ) => ( 1 , Some ( 1 ) ) ,
246
+ ( l, n) => ( 1 , cmp:: min ( l, n) . checked_add ( & 1 u) )
247
+ }
248
+ }
233
249
}
234
250
235
251
/// An iterator over the slices of a vector separated by elements that
@@ -242,6 +258,7 @@ pub struct RSplitIterator<'self, T> {
242
258
}
243
259
244
260
impl < ' self , T > Iterator < & ' self [ T ] > for RSplitIterator < ' self , T > {
261
+ #[ inline]
245
262
fn next ( & mut self ) -> Option < & ' self [ T ] > {
246
263
if self . finished { return None ; }
247
264
@@ -263,6 +280,18 @@ impl<'self, T> Iterator<&'self [T]> for RSplitIterator<'self, T> {
263
280
}
264
281
}
265
282
}
283
+
284
+ #[ inline]
285
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
286
+ if self . finished {
287
+ return ( 0 , Some ( 0 ) )
288
+ }
289
+ match ( self . v . len ( ) , self . n ) {
290
+ ( 0 , _) => ( 1 , Some ( 1 ) ) ,
291
+ ( _, 0 ) => ( 1 , Some ( 1 ) ) ,
292
+ ( l, n) => ( 1 , cmp:: min ( l, n) . checked_add ( & 1 u) )
293
+ }
294
+ }
266
295
}
267
296
268
297
// Appending
@@ -453,6 +482,7 @@ pub struct WindowIter<'self, T> {
453
482
}
454
483
455
484
impl < ' self , T > Iterator < & ' self [ T ] > for WindowIter < ' self , T > {
485
+ #[ inline]
456
486
fn next ( & mut self ) -> Option < & ' self [ T ] > {
457
487
if self . size > self . v . len ( ) {
458
488
None
@@ -462,6 +492,16 @@ impl<'self, T> Iterator<&'self [T]> for WindowIter<'self, T> {
462
492
ret
463
493
}
464
494
}
495
+
496
+ #[ inline]
497
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
498
+ if self . size > self . v . len ( ) {
499
+ ( 0 , Some ( 0 ) )
500
+ } else {
501
+ let x = self . v . len ( ) - self . size ;
502
+ ( x. saturating_add ( 1 ) , x. checked_add ( & 1 u) )
503
+ }
504
+ }
465
505
}
466
506
467
507
/// An iterator over a vector in (non-overlapping) chunks (`size`
@@ -476,6 +516,7 @@ pub struct ChunkIter<'self, T> {
476
516
}
477
517
478
518
impl < ' self , T > Iterator < & ' self [ T ] > for ChunkIter < ' self , T > {
519
+ #[ inline]
479
520
fn next ( & mut self ) -> Option < & ' self [ T ] > {
480
521
if self . v . len ( ) == 0 {
481
522
None
@@ -487,9 +528,21 @@ impl<'self, T> Iterator<&'self [T]> for ChunkIter<'self, T> {
487
528
Some ( fst)
488
529
}
489
530
}
531
+
532
+ #[ inline]
533
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
534
+ if self . v . len ( ) == 0 {
535
+ ( 0 , Some ( 0 ) )
536
+ } else {
537
+ let ( n, rem) = self . v . len ( ) . div_rem ( & self . size ) ;
538
+ let n = if rem > 0 { n+1 } else { n } ;
539
+ ( n, Some ( n) )
540
+ }
541
+ }
490
542
}
491
543
492
544
impl < ' self , T > DoubleEndedIterator < & ' self [ T ] > for ChunkIter < ' self , T > {
545
+ #[ inline]
493
546
fn next_back ( & mut self ) -> Option < & ' self [ T ] > {
494
547
if self . v . len ( ) == 0 {
495
548
None
@@ -2236,6 +2289,7 @@ impl<'self, T> RandomAccessIterator<&'self T> for VecIterator<'self, T> {
2236
2289
exact
2237
2290
}
2238
2291
2292
+ #[ inline]
2239
2293
fn idx ( & self , index : uint ) -> Option < & ' self T > {
2240
2294
unsafe {
2241
2295
if index < self . indexable ( ) {
@@ -2281,6 +2335,7 @@ pub struct MoveIterator<T> {
2281
2335
}
2282
2336
2283
2337
impl < T > Iterator < T > for MoveIterator < T > {
2338
+ #[ inline]
2284
2339
fn next ( & mut self ) -> Option < T > {
2285
2340
// this is peculiar, but is required for safety with respect
2286
2341
// to dtors. It traverses the first half of the vec, and
@@ -2298,6 +2353,12 @@ impl<T> Iterator<T> for MoveIterator<T> {
2298
2353
2299
2354
self . v . pop_opt ( )
2300
2355
}
2356
+
2357
+ #[ inline]
2358
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
2359
+ let l = self . v . len ( ) ;
2360
+ ( l, Some ( l) )
2361
+ }
2301
2362
}
2302
2363
2303
2364
/// An iterator that moves out of a vector in reverse order.
@@ -2307,9 +2368,16 @@ pub struct MoveRevIterator<T> {
2307
2368
}
2308
2369
2309
2370
impl < T > Iterator < T > for MoveRevIterator < T > {
2371
+ #[ inline]
2310
2372
fn next ( & mut self ) -> Option < T > {
2311
2373
self . v . pop_opt ( )
2312
2374
}
2375
+
2376
+ #[ inline]
2377
+ fn size_hint ( & self ) -> ( uint , Option < uint > ) {
2378
+ let l = self . v . len ( ) ;
2379
+ ( l, Some ( l) )
2380
+ }
2313
2381
}
2314
2382
2315
2383
impl < A > FromIterator < A > for ~[ A ] {
0 commit comments