@@ -39,7 +39,7 @@ fn process_change(
3939 // 3. `change` *must* be returned if it is not fully included in `hunk`.
4040 match ( hunk, change) {
4141 ( Some ( hunk) , Some ( Change :: Unchanged ( unchanged) ) ) => {
42- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) else {
42+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) else {
4343 // We don’t clone blame to `parent` as `suspect` has nothing to do with this
4444 // `hunk`.
4545 new_hunks_to_blame. push ( hunk) ;
@@ -102,7 +102,7 @@ fn process_change(
102102 }
103103 }
104104 ( Some ( hunk) , Some ( Change :: AddedOrReplaced ( added, number_of_lines_deleted) ) ) => {
105- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) . cloned ( ) else {
105+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) . cloned ( ) else {
106106 new_hunks_to_blame. push ( hunk) ;
107107 return ( None , Some ( Change :: AddedOrReplaced ( added, number_of_lines_deleted) ) ) ;
108108 } ;
@@ -247,7 +247,7 @@ fn process_change(
247247 }
248248 }
249249 ( Some ( hunk) , Some ( Change :: Deleted ( line_number_in_destination, number_of_lines_deleted) ) ) => {
250- let Some ( range_in_suspect) = hunk. suspects . get ( & suspect) else {
250+ let Some ( range_in_suspect) = hunk. get_range ( & suspect) else {
251251 new_hunks_to_blame. push ( hunk) ;
252252 return (
253253 None ,
@@ -359,12 +359,16 @@ fn process_changes(
359359
360360impl UnblamedHunk {
361361 fn shift_by ( mut self , suspect : ObjectId , offset : Offset ) -> Self {
362- self . suspects . entry ( suspect) . and_modify ( |e| * e = e. shift_by ( offset) ) ;
362+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == suspect) {
363+ if let Some ( ( _, ref mut range_in_suspect) ) = self . suspects . get_mut ( position) {
364+ * range_in_suspect = range_in_suspect. shift_by ( offset) ;
365+ }
366+ }
363367 self
364368 }
365369
366370 fn split_at ( self , suspect : ObjectId , line_number_in_destination : u32 ) -> Either < Self , ( Self , Self ) > {
367- match self . suspects . get ( & suspect) {
371+ match self . get_range ( & suspect) {
368372 None => Either :: Left ( self ) ,
369373 Some ( range_in_suspect) => {
370374 if !range_in_suspect. contains ( & line_number_in_destination) {
@@ -405,34 +409,38 @@ impl UnblamedHunk {
405409 /// This is like [`Self::pass_blame()`], but easier to use in places where the 'passing' is
406410 /// done 'inline'.
407411 fn passed_blame ( mut self , from : ObjectId , to : ObjectId ) -> Self {
408- if let Some ( range_in_suspect) = self . suspects . remove ( & from) {
409- self . suspects . insert ( to, range_in_suspect) ;
412+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == from) {
413+ if let Some ( ( ref mut commit_id, _) ) = self . suspects . get_mut ( position) {
414+ * commit_id = to;
415+ }
410416 }
411417 self
412418 }
413419
414420 /// Transfer all ranges from the commit at `from` to the commit at `to`.
415421 fn pass_blame ( & mut self , from : ObjectId , to : ObjectId ) {
416- if let Some ( range_in_suspect) = self . suspects . remove ( & from) {
417- self . suspects . insert ( to, range_in_suspect) ;
422+ if let Some ( position) = self . suspects . iter ( ) . position ( |entry| entry. 0 == from) {
423+ if let Some ( ( ref mut commit_id, _) ) = self . suspects . get_mut ( position) {
424+ * commit_id = to;
425+ }
418426 }
419427 }
420428
421429 fn clone_blame ( & mut self , from : ObjectId , to : ObjectId ) {
422- if let Some ( range_in_suspect) = self . suspects . get ( & from) {
423- self . suspects . insert ( to, range_in_suspect. clone ( ) ) ;
430+ if let Some ( range_in_suspect) = self . get_range ( & from) {
431+ self . suspects . push ( ( to, range_in_suspect. clone ( ) ) ) ;
424432 }
425433 }
426434
427435 fn remove_blame ( & mut self , suspect : ObjectId ) {
428- self . suspects . remove ( & suspect) ;
436+ self . suspects . retain ( |entry| entry . 0 != suspect) ;
429437 }
430438}
431439
432440impl BlameEntry {
433441 /// Create an offset from a portion of the *Blamed File*.
434442 fn from_unblamed_hunk ( unblamed_hunk : & UnblamedHunk , commit_id : ObjectId ) -> Option < Self > {
435- let range_in_source_file = unblamed_hunk. suspects . get ( & commit_id) ?;
443+ let range_in_source_file = unblamed_hunk. get_range ( & commit_id) ?;
436444
437445 Some ( Self {
438446 start_in_blamed_file : unblamed_hunk. range_in_blamed_file . start ,
0 commit comments