Skip to content

Commit

Permalink
Remove pointless vec copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Jun 13, 2022
1 parent 1c9e05e commit 95ba06a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/display/hunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,10 @@ fn either_side_equal(
false
}

pub fn matched_lines_for_hunk(
matched_lines: &[(Option<LineNumber>, Option<LineNumber>)],
pub fn matched_lines_for_hunk<'a>(
matched_lines: &'a [(Option<LineNumber>, Option<LineNumber>)],
hunk: &Hunk,
) -> Vec<(Option<LineNumber>, Option<LineNumber>)> {
) -> &'a [(Option<LineNumber>, Option<LineNumber>)] {
let mut hunk_lhs_novel = hunk.novel_lhs.iter().copied().collect::<Vec<_>>();
hunk_lhs_novel.sort();

Expand Down Expand Up @@ -645,7 +645,7 @@ pub fn matched_lines_for_hunk(
end_i = matched_lines.len();
}

matched_lines[start_i..end_i].to_vec()
&matched_lines[start_i..end_i]
}

#[cfg(test)]
Expand Down
18 changes: 9 additions & 9 deletions src/display/side_by_side.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,27 +406,27 @@ pub fn print(

let source_dims = SourceDimensions::new(
display_options.display_width,
&aligned_lines,
aligned_lines,
&lhs_lines,
&rhs_lines,
);
for (lhs_line_num, rhs_line_num) in aligned_lines {
let lhs_line_novel = highlight_as_novel(
lhs_line_num,
*lhs_line_num,
&lhs_lines,
rhs_line_num,
*rhs_line_num,
&lhs_lines_with_novel,
);
let rhs_line_novel = highlight_as_novel(
rhs_line_num,
*rhs_line_num,
&rhs_lines,
lhs_line_num,
*lhs_line_num,
&rhs_lines_with_novel,
);

let (display_lhs_line_num, display_rhs_line_num) = display_line_nums(
lhs_line_num,
rhs_line_num,
*lhs_line_num,
*rhs_line_num,
&source_dims,
display_options.use_color,
display_options.background_color,
Expand Down Expand Up @@ -554,10 +554,10 @@ pub fn print(
}

if lhs_line_num.is_some() {
prev_lhs_line_num = lhs_line_num;
prev_lhs_line_num = *lhs_line_num;
}
if rhs_line_num.is_some() {
prev_rhs_line_num = rhs_line_num;
prev_rhs_line_num = *rhs_line_num;
}
}
println!();
Expand Down

0 comments on commit 95ba06a

Please sign in to comment.