Printer: Remove unused state fields (#6548)

This commit is contained in:
Micha Reiser 2023-08-14 11:08:00 +02:00 committed by GitHub
parent 51ae47ad56
commit 24f42f0894
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 13 deletions

View file

@ -695,8 +695,6 @@ impl<'a> Printer<'a> {
.buffer .buffer
.push_str(self.options.line_ending.as_str()); .push_str(self.options.line_ending.as_str());
self.state.generated_line += 1;
self.state.generated_column = 0;
self.state.line_width = 0; self.state.line_width = 0;
// Fit's only tests if groups up to the first line break fit. // Fit's only tests if groups up to the first line break fit.
@ -704,12 +702,11 @@ impl<'a> Printer<'a> {
self.state.measured_group_fits = false; self.state.measured_group_fits = false;
} else { } else {
self.state.buffer.push(char); self.state.buffer.push(char);
self.state.generated_column += 1;
let char_width = if char == '\t' { let char_width = if char == '\t' {
self.options.tab_width as usize self.options.tab_width as u32
} else { } else {
char.width().unwrap_or(0) char.width().unwrap_or(0) as u32
}; };
self.state.line_width += char_width; self.state.line_width += char_width;
@ -744,9 +741,7 @@ struct PrinterState<'a> {
source_position: TextSize, source_position: TextSize,
pending_indent: Indention, pending_indent: Indention,
measured_group_fits: bool, measured_group_fits: bool,
generated_line: usize, line_width: u32,
generated_column: usize,
line_width: usize,
line_suffixes: LineSuffixes<'a>, line_suffixes: LineSuffixes<'a>,
verbatim_markers: Vec<TextRange>, verbatim_markers: Vec<TextRange>,
group_modes: GroupModes, group_modes: GroupModes,
@ -1256,12 +1251,12 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
fn fits_text(&mut self, text: &str, args: PrintElementArgs) -> Fits { fn fits_text(&mut self, text: &str, args: PrintElementArgs) -> Fits {
let indent = std::mem::take(&mut self.state.pending_indent); let indent = std::mem::take(&mut self.state.pending_indent);
self.state.line_width += indent.level() as usize * self.options().indent_width() as usize self.state.line_width +=
+ indent.align() as usize; indent.level() as u32 * self.options().indent_width() as u32 + indent.align() as u32;
for c in text.chars() { for c in text.chars() {
let char_width = match c { let char_width = match c {
'\t' => self.options().tab_width as usize, '\t' => self.options().tab_width as u32,
'\n' => { '\n' => {
if self.must_be_flat { if self.must_be_flat {
return Fits::No; return Fits::No;
@ -1275,7 +1270,7 @@ impl<'a, 'print> FitsMeasurer<'a, 'print> {
} }
}; };
} }
c => c.width().unwrap_or(0), c => c.width().unwrap_or(0) as u32,
}; };
self.state.line_width += char_width; self.state.line_width += char_width;
} }
@ -1369,7 +1364,7 @@ impl From<bool> for Fits {
struct FitsState { struct FitsState {
pending_indent: Indention, pending_indent: Indention,
has_line_suffix: bool, has_line_suffix: bool,
line_width: usize, line_width: u32,
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]

View file

@ -43,6 +43,12 @@ impl From<PrintWidth> for usize {
} }
} }
impl From<PrintWidth> for u32 {
fn from(width: PrintWidth) -> Self {
width.0
}
}
impl<'a, O> From<&'a O> for PrinterOptions impl<'a, O> From<&'a O> for PrinterOptions
where where
O: FormatOptions, O: FormatOptions,