Inline indent function

This commit is contained in:
David Tolnay 2022-01-19 18:55:24 -08:00
parent 9e794d7de3
commit 224536f4fe
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82

View file

@ -366,12 +366,7 @@ impl Printer {
fn print_newline(&mut self, amount: isize) { fn print_newline(&mut self, amount: isize) {
self.out.push('\n'); self.out.push('\n');
self.pending_indentation = 0; self.pending_indentation = amount;
self.indent(amount);
}
fn indent(&mut self, amount: isize) {
self.pending_indentation += amount;
} }
fn get_top(&self) -> PrintFrame { fn get_top(&self) -> PrintFrame {
@ -397,7 +392,7 @@ impl Printer {
fn print_break(&mut self, token: BreakToken, size: isize) { fn print_break(&mut self, token: BreakToken, size: isize) {
match self.get_top() { match self.get_top() {
PrintFrame::Fits => { PrintFrame::Fits => {
self.indent(token.blank_space); self.pending_indentation += token.blank_space;
self.space -= token.blank_space; self.space -= token.blank_space;
} }
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => { PrintFrame::Broken { offset, breaks: Breaks::Consistent } => {
@ -409,7 +404,7 @@ impl Printer {
self.print_newline(offset + token.offset); self.print_newline(offset + token.offset);
self.space = self.margin - (offset + token.offset); self.space = self.margin - (offset + token.offset);
} else { } else {
self.indent(token.blank_space); self.pending_indentation += token.blank_space;
self.space -= token.blank_space; self.space -= token.blank_space;
} }
} }