@@ -33,25 +33,31 @@ pub struct Decompositions<I> {
33
33
// to sort in canonical order and is not safe to emit.
34
34
buffer : SmallVec < [ ( u8 , char ) ; 4 ] > ,
35
35
ready : Range < usize > ,
36
+
37
+ // The only purpose of this field is to prevent us calling `next` on an
38
+ // exhausted iterator; otherwise it would be redundant.
39
+ done : bool ,
36
40
}
37
41
38
42
#[ inline]
39
- pub fn new_canonical < I : Iterator < Item = char > > ( iter : I ) -> Decompositions < I > {
43
+ pub fn new_canonical < I : Iterator < Item = char > > ( iter : I ) -> Decompositions < I > {
40
44
Decompositions {
41
45
kind : self :: DecompositionType :: Canonical ,
42
46
iter : iter,
43
47
buffer : SmallVec :: new ( ) ,
44
48
ready : 0 ..0 ,
49
+ done : false ,
45
50
}
46
51
}
47
52
48
53
#[ inline]
49
- pub fn new_compatible < I : Iterator < Item = char > > ( iter : I ) -> Decompositions < I > {
54
+ pub fn new_compatible < I : Iterator < Item = char > > ( iter : I ) -> Decompositions < I > {
50
55
Decompositions {
51
56
kind : self :: DecompositionType :: Compatible ,
52
57
iter : iter,
53
58
buffer : SmallVec :: new ( ) ,
54
59
ready : 0 ..0 ,
60
+ done : false ,
55
61
}
56
62
}
57
63
@@ -98,13 +104,14 @@ impl<I> Decompositions<I> {
98
104
}
99
105
}
100
106
101
- impl < I : Iterator < Item = char > > Iterator for Decompositions < I > {
107
+ impl < I : Iterator < Item = char > > Iterator for Decompositions < I > {
102
108
type Item = char ;
103
109
104
110
#[ inline]
105
111
fn next ( & mut self ) -> Option < char > {
106
112
while self . ready . end == 0 {
107
- match ( self . iter . next ( ) , & self . kind ) {
113
+ let next = if self . done { None } else { self . iter . next ( ) } ;
114
+ match ( next, & self . kind ) {
108
115
( Some ( ch) , & DecompositionType :: Canonical ) => {
109
116
super :: char:: decompose_canonical ( ch, |d| self . push_back ( d) ) ;
110
117
}
@@ -116,6 +123,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
116
123
return None ;
117
124
} else {
118
125
self . sort_pending ( ) ;
126
+ self . done = true ;
119
127
break ;
120
128
}
121
129
}
@@ -133,7 +141,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
133
141
}
134
142
}
135
143
136
- impl < I : Iterator < Item = char > + Clone > fmt:: Display for Decompositions < I > {
144
+ impl < I : Iterator < Item = char > + Clone > fmt:: Display for Decompositions < I > {
137
145
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
138
146
for c in self . clone ( ) {
139
147
f. write_char ( c) ?;
0 commit comments