Minor cleanups (#1235)

* Clean up manual min impl

* Only clone if necessary
This commit is contained in:
Dániel Buga 2022-09-16 21:29:44 +02:00 committed by GitHub
parent 07390f0c90
commit f73b4d961f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View File

@ -53,10 +53,7 @@ pub fn line_of_height(&self, height: usize) -> usize {
}
pub fn height_of_line(&self, line: usize) -> usize {
let max_line = self.0.len();
if line >= max_line {
return self.0.count::<LensMetric>(self.0.len());
}
let line = self.0.len().min(line);
self.0.count::<LensMetric>(line)
}

View File

@ -905,7 +905,7 @@ fn next_diff(&mut self, ctx: &mut EventCtx) {
let (path, offset) =
next_in_file_diff_offset(offset, buffer_path, &diff_files);
let location = EditorLocation {
path,
path: path.to_path_buf(),
position: Some(offset),
scroll_offset: None,
history: Some("head".to_string()),
@ -2433,24 +2433,24 @@ pub struct HighlightTextLayout {
pub highlights: Vec<(usize, usize, String)>,
}
fn next_in_file_diff_offset(
fn next_in_file_diff_offset<'a>(
offset: usize,
path: &Path,
file_diffs: &[(PathBuf, Vec<usize>)],
) -> (PathBuf, usize) {
file_diffs: &'a [(PathBuf, Vec<usize>)],
) -> (&'a Path, usize) {
for (current_path, offsets) in file_diffs {
if path == current_path {
for diff_offset in offsets {
if *diff_offset > offset {
return ((*current_path).clone(), *diff_offset);
return (current_path.as_ref(), *diff_offset);
}
}
}
if current_path > path {
return ((*current_path).clone(), offsets[0]);
return (current_path.as_ref(), offsets[0]);
}
}
((file_diffs[0].0).clone(), file_diffs[0].1[0])
(file_diffs[0].0.as_ref(), file_diffs[0].1[0])
}
fn next_in_file_errors_offset(