@@ -33,25 +33,31 @@ pub struct Decompositions<I> {
3333 // to sort in canonical order and is not safe to emit.
3434 buffer : SmallVec < [ ( u8 , char ) ; 4 ] > ,
3535 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 ,
3640}
3741
3842#[ 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 > {
4044 Decompositions {
4145 kind : self :: DecompositionType :: Canonical ,
4246 iter : iter,
4347 buffer : SmallVec :: new ( ) ,
4448 ready : 0 ..0 ,
49+ done : false ,
4550 }
4651}
4752
4853#[ 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 > {
5055 Decompositions {
5156 kind : self :: DecompositionType :: Compatible ,
5257 iter : iter,
5358 buffer : SmallVec :: new ( ) ,
5459 ready : 0 ..0 ,
60+ done : false ,
5561 }
5662}
5763
@@ -98,13 +104,14 @@ impl<I> Decompositions<I> {
98104 }
99105}
100106
101- impl < I : Iterator < Item = char > > Iterator for Decompositions < I > {
107+ impl < I : Iterator < Item = char > > Iterator for Decompositions < I > {
102108 type Item = char ;
103109
104110 #[ inline]
105111 fn next ( & mut self ) -> Option < char > {
106112 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 ) {
108115 ( Some ( ch) , & DecompositionType :: Canonical ) => {
109116 super :: char:: decompose_canonical ( ch, |d| self . push_back ( d) ) ;
110117 }
@@ -116,6 +123,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
116123 return None ;
117124 } else {
118125 self . sort_pending ( ) ;
126+ self . done = true ;
119127 break ;
120128 }
121129 }
@@ -133,7 +141,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
133141 }
134142}
135143
136- impl < I : Iterator < Item = char > + Clone > fmt:: Display for Decompositions < I > {
144+ impl < I : Iterator < Item = char > + Clone > fmt:: Display for Decompositions < I > {
137145 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
138146 for c in self . clone ( ) {
139147 f. write_char ( c) ?;
0 commit comments