Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement check_stack nonrecursively
  • Loading branch information
dtolnay committed Jan 19, 2022
commit a37d272892172dfe598d9df182fa908d74359c6e
19 changes: 10 additions & 9 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,27 +378,28 @@ impl Printer {
}
}

fn check_stack(&mut self, k: usize) {
if let Some(&x) = self.scan_stack.front() {
fn check_stack(&mut self, mut k: usize) {
while let Some(&x) = self.scan_stack.front() {
match self.buf[x].token {
Token::Begin(_) => {
if k > 0 {
self.scan_stack.pop_front().unwrap();
self.buf[x].size += self.right_total;
self.check_stack(k - 1);
if k == 0 {
break;
}
self.scan_stack.pop_front().unwrap();
self.buf[x].size += self.right_total;
k -= 1;
}
Token::End => {
// paper says + not =, but that makes no sense.
self.scan_stack.pop_front().unwrap();
self.buf[x].size = 1;
self.check_stack(k + 1);
k += 1;
}
_ => {
self.scan_stack.pop_front().unwrap();
self.buf[x].size += self.right_total;
if k > 0 {
self.check_stack(k);
if k == 0 {
break;
}
}
}
Expand Down