Skip to content

Pretty printer algorithm revamp step 2 #93065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jan 20, 2022
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
Inline Printer's scan_push method
  • Loading branch information
dtolnay committed Jan 19, 2022
commit e219b2b5f90bf48bf56533c16745f2ce85216a2c
14 changes: 6 additions & 8 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ impl Printer {
self.right += 1;
self.buf.advance_right();
}
self.scan_push(BufEntry { token: Token::Begin(b), size: -self.right_total });
self.buf[self.right] = BufEntry { token: Token::Begin(b), size: -self.right_total };
self.scan_stack.push_front(self.right);
}

fn scan_end(&mut self) {
Expand All @@ -302,7 +303,8 @@ impl Printer {
} else {
self.right += 1;
self.buf.advance_right();
self.scan_push(BufEntry { token: Token::End, size: -1 });
self.buf[self.right] = BufEntry { token: Token::End, size: -1 };
self.scan_stack.push_front(self.right);
}
}

Expand All @@ -317,7 +319,8 @@ impl Printer {
self.buf.advance_right();
}
self.check_stack(0);
self.scan_push(BufEntry { token: Token::Break(b), size: -self.right_total });
self.buf[self.right] = BufEntry { token: Token::Break(b), size: -self.right_total };
self.scan_stack.push_front(self.right);
self.right_total += b.blank_space;
}

Expand Down Expand Up @@ -347,11 +350,6 @@ impl Printer {
}
}

fn scan_push(&mut self, entry: BufEntry) {
self.buf[self.right] = entry;
self.scan_stack.push_front(self.right);
}

fn scan_pop(&mut self) -> usize {
self.scan_stack.pop_front().unwrap()
}
Expand Down