diff --git a/src/display/side_by_side.rs b/src/display/side_by_side.rs index df360b584f..f7d31825ef 100644 --- a/src/display/side_by_side.rs +++ b/src/display/side_by_side.rs @@ -18,7 +18,7 @@ use crate::{ BackgroundColor, }, hash::DftHashMap, - lines::{codepoint_len, format_line_num}, + lines::format_line_num, options::{DisplayMode, DisplayOptions}, parse::syntax::{zip_pad_shorter, MatchedPos}, summary::FileFormat, @@ -166,31 +166,16 @@ struct SourceDimensions { } impl SourceDimensions { - fn new( - terminal_width: usize, - line_nums: &[(Option, Option)], - lhs_lines: &[&str], - rhs_lines: &[&str], - ) -> Self { + fn new(terminal_width: usize, line_nums: &[(Option, Option)]) -> Self { let mut lhs_max_line: LineNumber = 1.into(); let mut rhs_max_line: LineNumber = 1.into(); - let mut lhs_max_content = 1; - let mut rhs_max_content = 1; for (lhs_line_num, rhs_line_num) in line_nums { if let Some(lhs_line_num) = lhs_line_num { lhs_max_line = max(lhs_max_line, *lhs_line_num); - lhs_max_content = max( - lhs_max_content, - codepoint_len(lhs_lines[lhs_line_num.as_usize()]), - ); } if let Some(rhs_line_num) = rhs_line_num { rhs_max_line = max(rhs_max_line, *rhs_line_num); - rhs_max_content = max( - rhs_max_content, - codepoint_len(rhs_lines[rhs_line_num.as_usize()]), - ); } } @@ -436,12 +421,7 @@ pub(crate) fn print( let no_rhs_changes = hunk.novel_rhs.is_empty(); let same_lines = aligned_lines.iter().all(|(l, r)| l == r); - let source_dims = SourceDimensions::new( - display_options.display_width, - aligned_lines, - &lhs_lines, - &rhs_lines, - ); + let source_dims = SourceDimensions::new(display_options.display_width, aligned_lines); for (lhs_line_num, rhs_line_num) in aligned_lines { let lhs_line_novel = highlight_as_novel( *lhs_line_num, @@ -606,14 +586,7 @@ mod tests { #[test] fn test_width_calculations() { let line_nums = [(Some(1.into()), Some(10.into()))]; - let source_dims = SourceDimensions::new( - 80, - &line_nums, - &"foo\nbar\n".lines().collect::>(), - &"x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n" - .lines() - .collect::>(), - ); + let source_dims = SourceDimensions::new(80, &line_nums); assert_eq!(source_dims.lhs_line_nums_width, 2); assert_eq!(source_dims.rhs_line_nums_width, 3); @@ -627,8 +600,6 @@ mod tests { (Some(0.into()), Some(0.into())), (Some(1.into()), Some(1.into())), ], - &"foo\nbar\n".lines().collect::>(), - &"fox\nbax\n".lines().collect::>(), ); assert_eq!( @@ -649,8 +620,6 @@ mod tests { (Some(0.into()), Some(0.into())), (Some(1.into()), Some(1.into())), ], - &"foo\nbar\n".lines().collect::>(), - &"fox\nbax\n".lines().collect::>(), ); assert_eq!( diff --git a/src/lines.rs b/src/lines.rs index 3589121296..a47182cd6e 100644 --- a/src/lines.rs +++ b/src/lines.rs @@ -16,12 +16,6 @@ struct LinePosition { column: usize, } -/// Return the length of `s` in codepoints. This is important when -/// finding character boundaries for slicing without errors. -pub(crate) fn codepoint_len(s: &str) -> usize { - s.chars().count() -} - /// Return the length of `s` in bytes. /// /// This is a trivial wrapper to make it clear when we want bytes not @@ -80,11 +74,6 @@ mod tests { assert_eq!(line.max_line().0, 1); } - #[test] - fn codepoint_len_non_ascii() { - assert_eq!(codepoint_len("ƒoo"), 3); - } - #[test] fn test_is_all_whiteapce() { assert!(is_all_whitespace(" \n\t"));