Skip to content

Commit 215a4d2

Browse files
author
David Judd
committed
Use fuse
1 parent eff13b0 commit 215a4d2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/decompose.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010
use smallvec::SmallVec;
1111
use std::fmt::{self, Write};
12+
use std::iter::Fuse;
1213
use std::ops::Range;
1314

1415
#[derive(Clone)]
@@ -21,7 +22,7 @@ enum DecompositionType {
2122
#[derive(Clone)]
2223
pub struct Decompositions<I> {
2324
kind: DecompositionType,
24-
iter: I,
25+
iter: Fuse<I>,
2526

2627
// This buffer stores pairs of (canonical combining class, character),
2728
// pushed onto the end in text order.
@@ -39,7 +40,7 @@ pub struct Decompositions<I> {
3940
pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
4041
Decompositions {
4142
kind: self::DecompositionType::Canonical,
42-
iter: iter,
43+
iter: iter.fuse(),
4344
buffer: SmallVec::new(),
4445
ready: 0..0,
4546
}
@@ -49,7 +50,7 @@ pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
4950
pub fn new_compatible<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
5051
Decompositions {
5152
kind: self::DecompositionType::Compatible,
52-
iter: iter,
53+
iter: iter.fuse(),
5354
buffer: SmallVec::new(),
5455
ready: 0..0,
5556
}
@@ -116,6 +117,11 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
116117
return None;
117118
} else {
118119
self.sort_pending();
120+
121+
// This implementation means that we can call `next`
122+
// on an exhausted iterator; the last outer `next` call
123+
// will result in an inner `next` call. To make this
124+
// safe, we use `fuse`.
119125
break;
120126
}
121127
}

0 commit comments

Comments
 (0)