File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ use crate::iter::{TrustedRandomAccess, TrustedRandomAccessNoCoerce};
8
8
use crate :: ops:: Try ;
9
9
use crate :: option;
10
10
use crate :: slice:: { self , Split as SliceSplit } ;
11
+ use core:: num:: NonZeroUsize ;
11
12
12
13
use super :: from_utf8_unchecked;
13
14
use super :: pattern:: Pattern ;
@@ -49,6 +50,22 @@ impl<'a> Iterator for Chars<'a> {
49
50
super :: count:: count_chars ( self . as_str ( ) )
50
51
}
51
52
53
+ #[ inline]
54
+ fn advance_by ( & mut self , mut remainder : usize ) -> Result < ( ) , NonZeroUsize > {
55
+ let bytes = & mut self . iter ;
56
+
57
+ while ( remainder > 0 ) && ( bytes. len ( ) > 0 ) {
58
+ remainder -= 1 ;
59
+ let b = bytes. as_slice ( ) [ 0 ] ;
60
+ let slurped = super :: validations:: utf8_char_width ( b) ;
61
+ // SAFETY: utf8-validity guarantees that the continuation bytes must be present
62
+ // and therefore we can skip this amount of bytes.
63
+ unsafe { bytes. advance_by ( slurped) . unwrap_unchecked ( ) } ;
64
+ }
65
+
66
+ NonZeroUsize :: new ( remainder) . map_or ( Ok ( ( ) ) , Err )
67
+ }
68
+
52
69
#[ inline]
53
70
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
54
71
let len = self . iter . len ( ) ;
You can’t perform that action at this time.
0 commit comments