Simplify left_total tracking

This commit is contained in:
David Tolnay 2022-01-19 18:36:29 -08:00
parent d981c5b354
commit 351011ec3f
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -321,20 +321,14 @@ impl Printer {
while left_size >= 0 { while left_size >= 0 {
let left = self.buf.pop_first().unwrap().token; let left = self.buf.pop_first().unwrap().token;
let len = match left { match &left {
Token::Break(b) => b.blank_space, Token::Break(b) => self.left_total += b.blank_space,
Token::String(ref s) => { Token::String(s) => self.left_total += s.len() as isize,
let len = s.len() as isize; _ => {}
assert_eq!(len, left_size);
len
} }
_ => 0,
};
self.print(left, left_size); self.print(left, left_size);
self.left_total += len;
if self.buf.is_empty() { if self.buf.is_empty() {
break; break;
} }
@ -447,11 +441,7 @@ impl Printer {
Token::Begin(b) => self.print_begin(*b, l), Token::Begin(b) => self.print_begin(*b, l),
Token::End => self.print_end(), Token::End => self.print_end(),
Token::Break(b) => self.print_break(*b, l), Token::Break(b) => self.print_break(*b, l),
Token::String(s) => { Token::String(s) => self.print_string(s),
let len = s.len() as isize;
assert_eq!(len, l);
self.print_string(s);
}
} }
self.last_printed = Some(token); self.last_printed = Some(token);
} }