Inline print_newline function

This commit is contained in:
David Tolnay 2022-01-19 18:56:12 -08:00
parent 224536f4fe
commit 51eeb82d9d
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
1 changed files with 4 additions and 7 deletions

View File

@ -364,11 +364,6 @@ impl Printer {
}
}
fn print_newline(&mut self, amount: isize) {
self.out.push('\n');
self.pending_indentation = amount;
}
fn get_top(&self) -> PrintFrame {
*self
.print_stack
@ -396,12 +391,14 @@ impl Printer {
self.space -= token.blank_space;
}
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => {
self.print_newline(offset + token.offset);
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
}
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
if size > self.space {
self.print_newline(offset + token.offset);
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
} else {
self.pending_indentation += token.blank_space;