Skip to content

Commit

Permalink
Index a single time in check_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 7, 2022
1 parent 87b904d commit c2d5b63
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,24 @@ impl Printer {

fn check_stack(&mut self, mut k: usize) {
while let Some(&x) = self.scan_stack.back() {
match self.buf[x].token {
let mut entry = &mut self.buf[x];
match entry.token {
Token::Begin(_) => {
if k == 0 {
break;
}
self.scan_stack.pop_back().unwrap();
self.buf[x].size += self.right_total;
entry.size += self.right_total;
k -= 1;
}
Token::End => {
self.scan_stack.pop_back().unwrap();
self.buf[x].size = 1;
entry.size = 1;
k += 1;
}
_ => {
self.scan_stack.pop_back().unwrap();
self.buf[x].size += self.right_total;
entry.size += self.right_total;
if k == 0 {
break;
}
Expand Down

0 comments on commit c2d5b63

Please sign in to comment.