Implement `FusedIterator` for `Instructions`
`Instructions` guarantee to return `None` from empty iterator so we should signal this in type system so that the code can be optimized better. This also adds a test to make sure this property holds.
This commit is contained in:
parent
51b1abdab2
commit
04a8f89f05
|
@ -744,6 +744,8 @@ impl<'a> Iterator for Instructions<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> ::core::iter::FusedIterator for Instructions<'a> {}
|
||||||
|
|
||||||
impl Builder {
|
impl Builder {
|
||||||
/// Creates a new empty script
|
/// Creates a new empty script
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
@ -1388,5 +1390,14 @@ mod test {
|
||||||
assert_eq!(script, ::bincode::deserialize(&bincode).unwrap());
|
assert_eq!(script, ::bincode::deserialize(&bincode).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_instructions_are_fused() {
|
||||||
|
let script = Script::new();
|
||||||
|
let mut instructions = script.instructions();
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
assert!(instructions.next().is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue