Skip to content

Commit

Permalink
Remove unused content length calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Nov 19, 2023
1 parent fe62cf4 commit 8fd79c2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 46 deletions.
39 changes: 4 additions & 35 deletions src/display/side_by_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -166,31 +166,16 @@ struct SourceDimensions {
}

impl SourceDimensions {
fn new(
terminal_width: usize,
line_nums: &[(Option<LineNumber>, Option<LineNumber>)],
lhs_lines: &[&str],
rhs_lines: &[&str],
) -> Self {
fn new(terminal_width: usize, line_nums: &[(Option<LineNumber>, Option<LineNumber>)]) -> 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()]),
);
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Vec<_>>(),
&"x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n"
.lines()
.collect::<Vec<_>>(),
);
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);
Expand All @@ -627,8 +600,6 @@ mod tests {
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
],
&"foo\nbar\n".lines().collect::<Vec<_>>(),
&"fox\nbax\n".lines().collect::<Vec<_>>(),
);

assert_eq!(
Expand All @@ -649,8 +620,6 @@ mod tests {
(Some(0.into()), Some(0.into())),
(Some(1.into()), Some(1.into())),
],
&"foo\nbar\n".lines().collect::<Vec<_>>(),
&"fox\nbax\n".lines().collect::<Vec<_>>(),
);

assert_eq!(
Expand Down
11 changes: 0 additions & 11 deletions src/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"));
Expand Down

0 comments on commit 8fd79c2

Please sign in to comment.