@@ -197,17 +197,10 @@ impl UnblamedHunk {
197
197
}
198
198
}
199
199
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) ) ;
206
202
207
- Self {
208
- range_in_blamed_file : self . range_in_blamed_file . clone ( ) ,
209
- suspects : new_suspects,
210
- }
203
+ self
211
204
}
212
205
213
206
fn split_at ( self , suspect : ObjectId , line_number_in_destination : u32 ) -> Either < Self , ( Self , Self ) > {
@@ -365,7 +358,7 @@ pub fn process_change(
365
358
// <--------> (hunk)
366
359
// <-------> (unchanged)
367
360
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) ) ;
369
362
370
363
( None , Some ( Change :: Unchanged ( unchanged) ) )
371
364
}
@@ -392,7 +385,7 @@ pub fn process_change(
392
385
// <---> (hunk)
393
386
// <----------> (unchanged)
394
387
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) ) ;
396
389
397
390
( None , Some ( Change :: Unchanged ( unchanged. clone ( ) ) ) )
398
391
}
@@ -417,7 +410,7 @@ pub fn process_change(
417
410
let new_hunk = match hunk. split_at ( suspect, added. start ) {
418
411
Either :: Left ( hunk) => hunk,
419
412
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) ) ;
421
414
422
415
after
423
416
}
@@ -446,7 +439,7 @@ pub fn process_change(
446
439
let new_hunk = match hunk. split_at ( suspect, added. start ) {
447
440
Either :: Left ( hunk) => hunk,
448
441
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) ) ;
450
443
451
444
after
452
445
}
@@ -507,7 +500,7 @@ pub fn process_change(
507
500
// <--> (hunk)
508
501
// <----> (added)
509
502
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) ) ;
511
504
512
505
( None , Some ( Change :: Added ( added. clone ( ) , number_of_lines_deleted) ) )
513
506
} else {
@@ -543,7 +536,7 @@ pub fn process_change(
543
536
let new_hunk = match hunk. split_at ( suspect, line_number_in_destination) {
544
537
Either :: Left ( hunk) => hunk,
545
538
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) ) ;
547
540
548
541
after
549
542
}
@@ -556,7 +549,7 @@ pub fn process_change(
556
549
// <---> (hunk)
557
550
// | (line_number_in_destination)
558
551
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) ) ;
560
553
561
554
(
562
555
None ,
@@ -565,7 +558,7 @@ pub fn process_change(
565
558
}
566
559
}
567
560
( 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) ) ;
569
562
570
563
( None , None )
571
564
}
0 commit comments