From 099fef3b728fc5eb2378b404fb3770e003aa7d0b Mon Sep 17 00:00:00 2001 From: David Judd Date: Tue, 15 Jan 2019 21:31:18 -0800 Subject: [PATCH] restore done field to Decompositions --- src/decompose.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/decompose.rs b/src/decompose.rs index 66954e5..37eaca5 100644 --- a/src/decompose.rs +++ b/src/decompose.rs @@ -33,25 +33,31 @@ pub struct Decompositions { // to sort in canonical order and is not safe to emit. buffer: SmallVec<[(u8, char); 4]>, ready: Range, + + // The only purpose of this field is to prevent us calling `next` on an + // exhausted iterator; otherwise it would be redundant. + done: bool, } #[inline] -pub fn new_canonical>(iter: I) -> Decompositions { +pub fn new_canonical>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Canonical, iter: iter, buffer: SmallVec::new(), ready: 0..0, + done: false, } } #[inline] -pub fn new_compatible>(iter: I) -> Decompositions { +pub fn new_compatible>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Compatible, iter: iter, buffer: SmallVec::new(), ready: 0..0, + done: false, } } @@ -98,13 +104,14 @@ impl Decompositions { } } -impl> Iterator for Decompositions { +impl> Iterator for Decompositions { type Item = char; #[inline] fn next(&mut self) -> Option { while self.ready.end == 0 { - match (self.iter.next(), &self.kind) { + let next = if self.done { None } else { self.iter.next() }; + match (next, &self.kind) { (Some(ch), &DecompositionType::Canonical) => { super::char::decompose_canonical(ch, |d| self.push_back(d)); } @@ -116,6 +123,7 @@ impl> Iterator for Decompositions { return None; } else { self.sort_pending(); + self.done = true; break; } } @@ -133,7 +141,7 @@ impl> Iterator for Decompositions { } } -impl + Clone> fmt::Display for Decompositions { +impl + Clone> fmt::Display for Decompositions { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for c in self.clone() { f.write_char(c)?;