Use Iterator::count() to check function stack depth

This commit is contained in:
Mahmoud Al-Qudsi 2024-05-30 12:49:28 -05:00
parent b495cffa50
commit f6200224fc

View file

@ -1059,11 +1059,12 @@ impl Parser {
return false;
}
// Count the functions.
let mut depth = 0;
let blocks = self.blocks();
for b in blocks.iter().rev() {
depth += if b.is_function_call() { 1 } else { 0 };
}
let depth = self
.blocks()
.iter()
.rev()
.filter(|b| b.is_function_call())
.count();
depth > FISH_MAX_STACK_DEPTH
}