Skip to content

Commit 1500c08

Browse files
committed
refactor
- don't use closures if they con't enclose state (or don't need to)
1 parent 4a78395 commit 1500c08

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

gix-blame/src/file/function.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,7 @@ where
9797
return Ok(Outcome::default());
9898
}
9999

100-
// This function assumes that `range` has 1-based inclusive line numbers and converts it to the
101-
// format internally used: 0-based line numbers stored in ranges that are exclusive at the
102-
// end.
103-
let one_based_inclusive_to_zero_based_exclusive_range = || -> Result<Range<u32>, Error> {
104-
if let Some(range) = range {
105-
if range.start == 0 {
106-
return Err(Error::InvalidLineRange);
107-
}
108-
let start = range.start - 1;
109-
let end = range.end;
110-
if start >= num_lines_in_blamed || end > num_lines_in_blamed || start == end {
111-
return Err(Error::InvalidLineRange);
112-
}
113-
Ok(start..end)
114-
} else {
115-
Ok(0..num_lines_in_blamed)
116-
}
117-
};
118-
119-
let range_in_blamed_file = one_based_inclusive_to_zero_based_exclusive_range()?;
120-
100+
let range_in_blamed_file = one_based_inclusive_to_zero_based_exclusive_range(range, num_lines_in_blamed)?;
121101
let mut hunks_to_blame = vec![UnblamedHunk {
122102
range_in_blamed_file: range_in_blamed_file.clone(),
123103
suspects: [(suspect, range_in_blamed_file)].into(),
@@ -283,6 +263,25 @@ where
283263
})
284264
}
285265

266+
/// This function assumes that `range` has 1-based inclusive line numbers and converts it to the
267+
/// format internally used: 0-based line numbers stored in ranges that are exclusive at the
268+
/// end.
269+
fn one_based_inclusive_to_zero_based_exclusive_range(
270+
range: Option<Range<u32>>,
271+
max_lines: u32,
272+
) -> Result<Range<u32>, Error> {
273+
let Some(range) = range else { return Ok(0..max_lines) };
274+
if range.start == 0 {
275+
return Err(Error::InvalidLineRange);
276+
}
277+
let start = range.start - 1;
278+
let end = range.end;
279+
if start >= max_lines || end > max_lines || start == end {
280+
return Err(Error::InvalidLineRange);
281+
}
282+
Ok(start..end)
283+
}
284+
286285
/// Pass ownership of each unblamed hunk of `from` to `to`.
287286
///
288287
/// This happens when `from` didn't actually change anything in the blamed file.

0 commit comments

Comments
 (0)