Skip to content

Commit a37d272

Browse files
committed
Implement check_stack nonrecursively
1 parent 0490e43 commit a37d272

File tree

1 file changed

+10
-9
lines changed
  • compiler/rustc_ast_pretty/src

1 file changed

+10
-9
lines changed

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,27 +378,28 @@ impl Printer {
378378
}
379379
}
380380

381-
fn check_stack(&mut self, k: usize) {
382-
if let Some(&x) = self.scan_stack.front() {
381+
fn check_stack(&mut self, mut k: usize) {
382+
while let Some(&x) = self.scan_stack.front() {
383383
match self.buf[x].token {
384384
Token::Begin(_) => {
385-
if k > 0 {
386-
self.scan_stack.pop_front().unwrap();
387-
self.buf[x].size += self.right_total;
388-
self.check_stack(k - 1);
385+
if k == 0 {
386+
break;
389387
}
388+
self.scan_stack.pop_front().unwrap();
389+
self.buf[x].size += self.right_total;
390+
k -= 1;
390391
}
391392
Token::End => {
392393
// paper says + not =, but that makes no sense.
393394
self.scan_stack.pop_front().unwrap();
394395
self.buf[x].size = 1;
395-
self.check_stack(k + 1);
396+
k += 1;
396397
}
397398
_ => {
398399
self.scan_stack.pop_front().unwrap();
399400
self.buf[x].size += self.right_total;
400-
if k > 0 {
401-
self.check_stack(k);
401+
if k == 0 {
402+
break;
402403
}
403404
}
404405
}

0 commit comments

Comments
 (0)