Skip to content

Commit dc3c7c9

Browse files
authored
Merge pull request #1978 from cruessler/make-mutation-more-idiomatic
Make mutation in `gix_blame::types::UnblamedHunk` more idiomatic
2 parents 800738a + 4423cae commit dc3c7c9

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

gix-blame/src/file/function.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ fn coalesce_blame_entries(lines_blamed: Vec<BlameEntry>) -> Vec<BlameEntry> {
401401
// As of 2024-09-19, the check below only is in `git`, but not in `libgit2`.
402402
&& previous_source_range.end == current_source_range.start
403403
{
404-
// let combined_range =
405404
let coalesced_entry = BlameEntry {
406405
start_in_blamed_file: previous_blamed_range.start as u32,
407406
start_in_source_file: previous_source_range.start as u32,

gix-blame/src/file/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,8 @@ fn process_changes(
357357

358358
impl UnblamedHunk {
359359
fn shift_by(mut self, suspect: ObjectId, offset: Offset) -> Self {
360-
if let Some(position) = self.suspects.iter().position(|entry| entry.0 == suspect) {
361-
if let Some((_, ref mut range_in_suspect)) = self.suspects.get_mut(position) {
362-
*range_in_suspect = range_in_suspect.shift_by(offset);
363-
}
360+
if let Some(entry) = self.suspects.iter_mut().find(|entry| entry.0 == suspect) {
361+
entry.1 = entry.1.shift_by(offset);
364362
}
365363
self
366364
}
@@ -407,20 +405,16 @@ impl UnblamedHunk {
407405
/// This is like [`Self::pass_blame()`], but easier to use in places where the 'passing' is
408406
/// done 'inline'.
409407
fn passed_blame(mut self, from: ObjectId, to: ObjectId) -> Self {
410-
if let Some(position) = self.suspects.iter().position(|entry| entry.0 == from) {
411-
if let Some((ref mut commit_id, _)) = self.suspects.get_mut(position) {
412-
*commit_id = to;
413-
}
408+
if let Some(entry) = self.suspects.iter_mut().find(|entry| entry.0 == from) {
409+
entry.0 = to;
414410
}
415411
self
416412
}
417413

418414
/// Transfer all ranges from the commit at `from` to the commit at `to`.
419415
fn pass_blame(&mut self, from: ObjectId, to: ObjectId) {
420-
if let Some(position) = self.suspects.iter().position(|entry| entry.0 == from) {
421-
if let Some((ref mut commit_id, _)) = self.suspects.get_mut(position) {
422-
*commit_id = to;
423-
}
416+
if let Some(entry) = self.suspects.iter_mut().find(|entry| entry.0 == from) {
417+
entry.0 = to;
424418
}
425419
}
426420

0 commit comments

Comments
 (0)