@@ -197,7 +197,6 @@ static void drop_origin_blob(struct origin *o)
197
197
* scoreboard structure, sorted by the target line number.
198
198
*/
199
199
struct blame_entry {
200
- struct blame_entry * prev ;
201
200
struct blame_entry * next ;
202
201
203
202
/* the first line of this group in the final image;
@@ -256,15 +255,6 @@ struct scoreboard {
256
255
int * lineno ;
257
256
};
258
257
259
- static inline int same_suspect (struct origin * a , struct origin * b )
260
- {
261
- if (a == b )
262
- return 1 ;
263
- if (a -> commit != b -> commit )
264
- return 0 ;
265
- return !strcmp (a -> path , b -> path );
266
- }
267
-
268
258
static void sanity_check_refcnt (struct scoreboard * );
269
259
270
260
/*
@@ -277,13 +267,11 @@ static void coalesce(struct scoreboard *sb)
277
267
struct blame_entry * ent , * next ;
278
268
279
269
for (ent = sb -> ent ; ent && (next = ent -> next ); ent = next ) {
280
- if (same_suspect ( ent -> suspect , next -> suspect ) &&
270
+ if (ent -> suspect == next -> suspect &&
281
271
ent -> guilty == next -> guilty &&
282
272
ent -> s_lno + ent -> num_lines == next -> s_lno ) {
283
273
ent -> num_lines += next -> num_lines ;
284
274
ent -> next = next -> next ;
285
- if (ent -> next )
286
- ent -> next -> prev = ent ;
287
275
origin_decref (next -> suspect );
288
276
free (next );
289
277
ent -> score = 0 ;
@@ -534,7 +522,7 @@ static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
534
522
prev = ent ;
535
523
536
524
/* prev, if not NULL, is the last one that is below e */
537
- e -> prev = prev ;
525
+
538
526
if (prev ) {
539
527
e -> next = prev -> next ;
540
528
prev -> next = e ;
@@ -543,8 +531,6 @@ static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
543
531
e -> next = sb -> ent ;
544
532
sb -> ent = e ;
545
533
}
546
- if (e -> next )
547
- e -> next -> prev = e ;
548
534
}
549
535
550
536
/*
@@ -555,14 +541,12 @@ static void add_blame_entry(struct scoreboard *sb, struct blame_entry *e)
555
541
*/
556
542
static void dup_entry (struct blame_entry * dst , struct blame_entry * src )
557
543
{
558
- struct blame_entry * p , * n ;
544
+ struct blame_entry * n ;
559
545
560
- p = dst -> prev ;
561
546
n = dst -> next ;
562
547
origin_incref (src -> suspect );
563
548
origin_decref (dst -> suspect );
564
549
memcpy (dst , src , sizeof (* src ));
565
- dst -> prev = p ;
566
550
dst -> next = n ;
567
551
dst -> score = 0 ;
568
552
}
@@ -742,7 +726,7 @@ static int find_last_in_target(struct scoreboard *sb, struct origin *target)
742
726
int last_in_target = -1 ;
743
727
744
728
for (e = sb -> ent ; e ; e = e -> next ) {
745
- if (e -> guilty || ! same_suspect ( e -> suspect , target ) )
729
+ if (e -> guilty || e -> suspect != target )
746
730
continue ;
747
731
if (last_in_target < e -> s_lno + e -> num_lines )
748
732
last_in_target = e -> s_lno + e -> num_lines ;
@@ -762,7 +746,7 @@ static void blame_chunk(struct scoreboard *sb,
762
746
struct blame_entry * e ;
763
747
764
748
for (e = sb -> ent ; e ; e = e -> next ) {
765
- if (e -> guilty || ! same_suspect ( e -> suspect , target ) )
749
+ if (e -> guilty || e -> suspect != target )
766
750
continue ;
767
751
if (same <= e -> s_lno )
768
752
continue ;
@@ -939,7 +923,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
939
923
mmfile_t * file_p )
940
924
{
941
925
const char * cp ;
942
- int cnt ;
943
926
mmfile_t file_o ;
944
927
struct handle_split_cb_data d ;
945
928
@@ -950,13 +933,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
950
933
*/
951
934
cp = nth_line (sb , ent -> lno );
952
935
file_o .ptr = (char * ) cp ;
953
- cnt = ent -> num_lines ;
954
-
955
- while (cnt && cp < sb -> final_buf + sb -> final_buf_size ) {
956
- if (* cp ++ == '\n' )
957
- cnt -- ;
958
- }
959
- file_o .size = cp - file_o .ptr ;
936
+ file_o .size = nth_line (sb , ent -> lno + ent -> num_lines ) - cp ;
960
937
961
938
/*
962
939
* file_o is a part of final image we are annotating.
@@ -992,7 +969,7 @@ static int find_move_in_parent(struct scoreboard *sb,
992
969
while (made_progress ) {
993
970
made_progress = 0 ;
994
971
for (e = sb -> ent ; e ; e = e -> next ) {
995
- if (e -> guilty || ! same_suspect ( e -> suspect , target ) ||
972
+ if (e -> guilty || e -> suspect != target ||
996
973
ent_score (sb , e ) < blame_move_score )
997
974
continue ;
998
975
find_copy_in_blob (sb , e , parent , split , & file_p );
@@ -1027,14 +1004,14 @@ static struct blame_list *setup_blame_list(struct scoreboard *sb,
1027
1004
1028
1005
for (e = sb -> ent , num_ents = 0 ; e ; e = e -> next )
1029
1006
if (!e -> scanned && !e -> guilty &&
1030
- same_suspect ( e -> suspect , target ) &&
1007
+ e -> suspect == target &&
1031
1008
min_score < ent_score (sb , e ))
1032
1009
num_ents ++ ;
1033
1010
if (num_ents ) {
1034
1011
blame_list = xcalloc (num_ents , sizeof (struct blame_list ));
1035
1012
for (e = sb -> ent , i = 0 ; e ; e = e -> next )
1036
1013
if (!e -> scanned && !e -> guilty &&
1037
- same_suspect ( e -> suspect , target ) &&
1014
+ e -> suspect == target &&
1038
1015
min_score < ent_score (sb , e ))
1039
1016
blame_list [i ++ ].ent = e ;
1040
1017
}
@@ -1178,7 +1155,7 @@ static void pass_whole_blame(struct scoreboard *sb,
1178
1155
origin -> file .ptr = NULL ;
1179
1156
}
1180
1157
for (e = sb -> ent ; e ; e = e -> next ) {
1181
- if (! same_suspect ( e -> suspect , origin ) )
1158
+ if (e -> suspect != origin )
1182
1159
continue ;
1183
1160
origin_incref (porigin );
1184
1161
origin_decref (e -> suspect );
@@ -1567,7 +1544,7 @@ static void assign_blame(struct scoreboard *sb, int opt)
1567
1544
1568
1545
/* Take responsibility for the remaining entries */
1569
1546
for (ent = sb -> ent ; ent ; ent = ent -> next )
1570
- if (same_suspect ( ent -> suspect , suspect ) )
1547
+ if (ent -> suspect == suspect )
1571
1548
found_guilty_entry (ent );
1572
1549
origin_decref (suspect );
1573
1550
@@ -1772,25 +1749,41 @@ static int prepare_lines(struct scoreboard *sb)
1772
1749
{
1773
1750
const char * buf = sb -> final_buf ;
1774
1751
unsigned long len = sb -> final_buf_size ;
1775
- int num = 0 , incomplete = 0 , bol = 1 ;
1752
+ const char * end = buf + len ;
1753
+ const char * p ;
1754
+ int * lineno ;
1755
+ int num = 0 , incomplete = 0 ;
1776
1756
1777
- if (len && buf [len - 1 ] != '\n' )
1778
- incomplete ++ ; /* incomplete line at the end */
1779
- while (len -- ) {
1780
- if (bol ) {
1781
- sb -> lineno = xrealloc (sb -> lineno ,
1782
- sizeof (int * ) * (num + 1 ));
1783
- sb -> lineno [num ] = buf - sb -> final_buf ;
1784
- bol = 0 ;
1785
- }
1786
- if (* buf ++ == '\n' ) {
1757
+ for (p = buf ;;) {
1758
+ p = memchr (p , '\n' , end - p );
1759
+ if (p ) {
1760
+ p ++ ;
1787
1761
num ++ ;
1788
- bol = 1 ;
1762
+ continue ;
1789
1763
}
1764
+ break ;
1790
1765
}
1791
- sb -> lineno = xrealloc (sb -> lineno ,
1792
- sizeof (int * ) * (num + incomplete + 1 ));
1793
- sb -> lineno [num + incomplete ] = buf - sb -> final_buf ;
1766
+
1767
+ if (len && end [-1 ] != '\n' )
1768
+ incomplete ++ ; /* incomplete line at the end */
1769
+
1770
+ sb -> lineno = xmalloc (sizeof (* sb -> lineno ) * (num + incomplete + 1 ));
1771
+ lineno = sb -> lineno ;
1772
+
1773
+ * lineno ++ = 0 ;
1774
+ for (p = buf ;;) {
1775
+ p = memchr (p , '\n' , end - p );
1776
+ if (p ) {
1777
+ p ++ ;
1778
+ * lineno ++ = p - buf ;
1779
+ continue ;
1780
+ }
1781
+ break ;
1782
+ }
1783
+
1784
+ if (incomplete )
1785
+ * lineno ++ = len ;
1786
+
1794
1787
sb -> num_lines = num + incomplete ;
1795
1788
return sb -> num_lines ;
1796
1789
}
@@ -2502,8 +2495,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2502
2495
ent -> suspect = o ;
2503
2496
ent -> s_lno = bottom ;
2504
2497
ent -> next = next ;
2505
- if (next )
2506
- next -> prev = ent ;
2507
2498
origin_incref (o );
2508
2499
}
2509
2500
origin_decref (o );
0 commit comments