File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -119,15 +119,25 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
119
119
120
120
#[ inline]
121
121
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
122
- let ( low, high) = self . iter . size_hint ( ) ;
122
+ let ( mut low, mut high) = self . iter . size_hint ( ) ;
123
123
// we could be entirely valid surrogates (2 elements per
124
124
// char), or entirely non-surrogates (1 element per char)
125
125
//
126
126
// In addition to `self.iter`, there's potentially one
127
127
// additional number in `self.buf`.
128
128
// On odd lower bound, at least one element must stay unpaired
129
129
// (with other elements from `self.iter`).
130
- ( low. div_ceil ( 2 ) , try { high?. checked_add ( 1 ) ? } )
130
+ //
131
+ // `self.buf` will never contain the first part of a surrogate,
132
+ // so the presence of `buf == Some(...)` always means +1
133
+ // on lower and upper bound.
134
+
135
+ low = low. div_ceil ( 2 ) ;
136
+ if self . buf . is_some ( ) {
137
+ low += 1 ;
138
+ high = try { high?. checked_add ( 1 ) ? }
139
+ }
140
+ ( low, high)
131
141
}
132
142
}
133
143
You can’t perform that action at this time.
0 commit comments