summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2024-02-22 23:24:49 -0500
committerKyle Martin <krm504@nyu.edu>2024-03-18 17:46:37 -0400
commita42eb98daba8d96a58b12da08c8ad879da351955 (patch)
tree526e7d79764aa252aae3a02b2d81dbf1b0533ba0 /rust/src
parent881318f0321c196ca5d87639e6e05796c39f04da (diff)
Cleaner zero-len condition
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/operand_iter.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/rust/src/operand_iter.rs b/rust/src/operand_iter.rs
index ba2bce7c..eca92cf3 100644
--- a/rust/src/operand_iter.rs
+++ b/rust/src/operand_iter.rs
@@ -13,10 +13,12 @@ pub struct OperandIter<F: ILFunction + RefCountable> {
impl<F: ILFunction + RefCountable> OperandIter<F> {
pub(crate) fn new(function: &F, idx: usize, number: usize) -> Self {
+ // Zero-length lists immediately finish iteration
+ let next_iter_idx = if number > 0 { Some(idx) } else { None };
Self {
function: function.to_owned(),
remaining: number,
- next_iter_idx: Some(idx),
+ next_iter_idx,
current_iter: OperandIterInner::empty(),
}
}
@@ -45,8 +47,6 @@ impl<F: ILFunction + RefCountable> Iterator for OperandIter<F> {
if let Some(item) = self.current_iter.next() {
self.remaining -= 1;
Some(item)
- } else if self.remaining == 0 {
- None // Only reached if initial length is 0
} else {
// Will short-circuit and return `None` once iter is exhausted
let iter_idx = self.next_iter_idx?;