Skip to content

Commit

Permalink
refactor: Extract get_max_lineno free function
Browse files Browse the repository at this point in the history
  • Loading branch information
chengr4 committed Aug 27, 2024
1 parent 7c5d667 commit 0c21810
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/renderer/display_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ impl<'a> fmt::Debug for DisplayList<'a> {

impl<'a> Display for DisplayList<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let max_lineno = self.body.iter().fold(None, |max, set| {
set.display_lines.iter().fold(max, |max, line| match line {
DisplayLine::Source { lineno, .. } => std::cmp::max(max, *lineno),
_ => max,
})
});
let max_lineno = get_max_lineno(&self.body);
let lineno_width = match max_lineno {
None => 0,
Some(_max) if self.anonymized_line_numbers => ANONYMIZED_LINE_NUM.len(),
Expand Down Expand Up @@ -149,6 +144,16 @@ impl<'a> DisplayList<'a> {
}
}

fn get_max_lineno(body: &Vec<DisplaySet<'_>>) -> Option<usize> {

Check failure

Code scanning / clippy

writing &Vec instead of &[_] involves a new object where a slice will do Error

writing &Vec instead of &[\_] involves a new object where a slice will do
let max_lineno = body.iter().fold(None, |max, set| {
set.display_lines.iter().fold(max, |max, line| match line {
DisplayLine::Source { lineno, .. } => std::cmp::max(max, *lineno),

Check failure

Code scanning / clippy

unnecessary qualification Error

unnecessary qualification
_ => max,
})
});
max_lineno
}

#[derive(Debug, PartialEq)]
pub(crate) struct DisplaySet<'a> {
pub(crate) display_lines: Vec<DisplayLine<'a>>,
Expand Down

0 comments on commit 0c21810

Please sign in to comment.