From c6524d31d431f64bb5df2c7bb504c2229d229507 Mon Sep 17 00:00:00 2001 From: David Judd Date: Thu, 17 Jan 2019 08:28:15 -0800 Subject: [PATCH] Use fuse --- src/decompose.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/decompose.rs b/src/decompose.rs index 66954e5..368d1fe 100644 --- a/src/decompose.rs +++ b/src/decompose.rs @@ -9,6 +9,7 @@ // except according to those terms. use smallvec::SmallVec; use std::fmt::{self, Write}; +use std::iter::Fuse; use std::ops::Range; #[derive(Clone)] @@ -21,7 +22,7 @@ enum DecompositionType { #[derive(Clone)] pub struct Decompositions { kind: DecompositionType, - iter: I, + iter: Fuse, // This buffer stores pairs of (canonical combining class, character), // pushed onto the end in text order. @@ -39,7 +40,7 @@ pub struct Decompositions { pub fn new_canonical>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Canonical, - iter: iter, + iter: iter.fuse(), buffer: SmallVec::new(), ready: 0..0, } @@ -49,7 +50,7 @@ pub fn new_canonical>(iter: I) -> Decompositions { pub fn new_compatible>(iter: I) -> Decompositions { Decompositions { kind: self::DecompositionType::Compatible, - iter: iter, + iter: iter.fuse(), buffer: SmallVec::new(), ready: 0..0, } @@ -116,6 +117,11 @@ impl> Iterator for Decompositions { return None; } else { self.sort_pending(); + + // This implementation means that we can call `next` + // on an exhausted iterator; the last outer `next` call + // will result in an inner `next` call. To make this + // safe, we use `fuse`. break; } }