@@ -197,17 +197,10 @@ impl UnblamedHunk {
197197 }
198198 }
199199
200- fn shift_by ( & self , offset : Offset ) -> Self {
201- let new_suspects = self
202- . suspects
203- . iter ( )
204- . map ( |( suspect, range) | ( * suspect, range. shift_by ( offset) ) )
205- . collect ( ) ;
200+ fn shift_by ( mut self , suspect : ObjectId , offset : Offset ) -> Self {
201+ self . suspects . entry ( suspect) . and_modify ( |e| * e = e. shift_by ( offset) ) ;
206202
207- Self {
208- range_in_blamed_file : self . range_in_blamed_file . clone ( ) ,
209- suspects : new_suspects,
210- }
203+ self
211204 }
212205
213206 fn split_at ( self , suspect : ObjectId , line_number_in_destination : u32 ) -> Either < Self , ( Self , Self ) > {
@@ -365,7 +358,7 @@ pub fn process_change(
365358 // <--------> (hunk)
366359 // <-------> (unchanged)
367360
368- new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
361+ new_hunks_to_blame. push ( hunk. shift_by ( suspect , * offset_in_destination) ) ;
369362
370363 ( None , Some ( Change :: Unchanged ( unchanged) ) )
371364 }
@@ -392,7 +385,7 @@ pub fn process_change(
392385 // <---> (hunk)
393386 // <----------> (unchanged)
394387
395- new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
388+ new_hunks_to_blame. push ( hunk. shift_by ( suspect , * offset_in_destination) ) ;
396389
397390 ( None , Some ( Change :: Unchanged ( unchanged. clone ( ) ) ) )
398391 }
@@ -417,7 +410,7 @@ pub fn process_change(
417410 let new_hunk = match hunk. split_at ( suspect, added. start ) {
418411 Either :: Left ( hunk) => hunk,
419412 Either :: Right ( ( before, after) ) => {
420- new_hunks_to_blame. push ( before. shift_by ( * offset_in_destination) ) ;
413+ new_hunks_to_blame. push ( before. shift_by ( suspect , * offset_in_destination) ) ;
421414
422415 after
423416 }
@@ -446,7 +439,7 @@ pub fn process_change(
446439 let new_hunk = match hunk. split_at ( suspect, added. start ) {
447440 Either :: Left ( hunk) => hunk,
448441 Either :: Right ( ( before, after) ) => {
449- new_hunks_to_blame. push ( before. shift_by ( * offset_in_destination) ) ;
442+ new_hunks_to_blame. push ( before. shift_by ( suspect , * offset_in_destination) ) ;
450443
451444 after
452445 }
@@ -507,7 +500,7 @@ pub fn process_change(
507500 // <--> (hunk)
508501 // <----> (added)
509502
510- new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
503+ new_hunks_to_blame. push ( hunk. shift_by ( suspect , * offset_in_destination) ) ;
511504
512505 ( None , Some ( Change :: Added ( added. clone ( ) , number_of_lines_deleted) ) )
513506 } else {
@@ -543,7 +536,7 @@ pub fn process_change(
543536 let new_hunk = match hunk. split_at ( suspect, line_number_in_destination) {
544537 Either :: Left ( hunk) => hunk,
545538 Either :: Right ( ( before, after) ) => {
546- new_hunks_to_blame. push ( before. shift_by ( * offset_in_destination) ) ;
539+ new_hunks_to_blame. push ( before. shift_by ( suspect , * offset_in_destination) ) ;
547540
548541 after
549542 }
@@ -556,7 +549,7 @@ pub fn process_change(
556549 // <---> (hunk)
557550 // | (line_number_in_destination)
558551
559- new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
552+ new_hunks_to_blame. push ( hunk. shift_by ( suspect , * offset_in_destination) ) ;
560553
561554 (
562555 None ,
@@ -565,7 +558,7 @@ pub fn process_change(
565558 }
566559 }
567560 ( Some ( hunk) , None ) => {
568- new_hunks_to_blame. push ( hunk. shift_by ( * offset_in_destination) ) ;
561+ new_hunks_to_blame. push ( hunk. shift_by ( suspect , * offset_in_destination) ) ;
569562
570563 ( None , None )
571564 }
0 commit comments