Skip to content

Commit 47c30f7

Browse files
rscharfegitster
authored andcommitted
blame: use DEFINE_LIST_SORT
Build a typed sort function for blame entries using DEFINE_LIST_SORT instead of calling llist_mergesort(). This gets rid of the next pointer accessor functions and their calling overhead at the cost of a slightly increased object text size. Before: __TEXT __DATA __OBJC others dec hex 24621 56 0 147515 172192 2a0a0 blame.o With this patch: __TEXT __DATA __OBJC others dec hex 25229 56 0 151702 176987 2b35b blame.o Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b378c2f commit 47c30f7

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

blame.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,30 +1098,22 @@ static struct blame_entry *blame_merge(struct blame_entry *list1,
10981098
}
10991099
}
11001100

1101-
static void *get_next_blame(const void *p)
1102-
{
1103-
return ((struct blame_entry *)p)->next;
1104-
}
1105-
1106-
static void set_next_blame(void *p1, void *p2)
1107-
{
1108-
((struct blame_entry *)p1)->next = p2;
1109-
}
1101+
DEFINE_LIST_SORT(static, sort_blame_entries, struct blame_entry, next);
11101102

11111103
/*
11121104
* Final image line numbers are all different, so we don't need a
11131105
* three-way comparison here.
11141106
*/
11151107

1116-
static int compare_blame_final(const void *p1, const void *p2)
1108+
static int compare_blame_final(const struct blame_entry *e1,
1109+
const struct blame_entry *e2)
11171110
{
1118-
return ((struct blame_entry *)p1)->lno > ((struct blame_entry *)p2)->lno
1119-
? 1 : -1;
1111+
return e1->lno > e2->lno ? 1 : -1;
11201112
}
11211113

1122-
static int compare_blame_suspect(const void *p1, const void *p2)
1114+
static int compare_blame_suspect(const struct blame_entry *s1,
1115+
const struct blame_entry *s2)
11231116
{
1124-
const struct blame_entry *s1 = p1, *s2 = p2;
11251117
/*
11261118
* to allow for collating suspects, we sort according to the
11271119
* respective pointer value as the primary sorting criterion.
@@ -1138,8 +1130,7 @@ static int compare_blame_suspect(const void *p1, const void *p2)
11381130

11391131
void blame_sort_final(struct blame_scoreboard *sb)
11401132
{
1141-
sb->ent = llist_mergesort(sb->ent, get_next_blame, set_next_blame,
1142-
compare_blame_final);
1133+
sort_blame_entries(&sb->ent, compare_blame_final);
11431134
}
11441135

11451136
static int compare_commits_by_reverse_commit_date(const void *a,
@@ -1964,9 +1955,7 @@ static void pass_blame_to_parent(struct blame_scoreboard *sb,
19641955
parent, target, 0);
19651956
*d.dstq = NULL;
19661957
if (ignore_diffs)
1967-
newdest = llist_mergesort(newdest, get_next_blame,
1968-
set_next_blame,
1969-
compare_blame_suspect);
1958+
sort_blame_entries(&newdest, compare_blame_suspect);
19701959
queue_blames(sb, parent, newdest);
19711960

19721961
return;
@@ -2383,8 +2372,7 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit, int reve
23832372
*/
23842373
static void distribute_blame(struct blame_scoreboard *sb, struct blame_entry *blamed)
23852374
{
2386-
blamed = llist_mergesort(blamed, get_next_blame, set_next_blame,
2387-
compare_blame_suspect);
2375+
sort_blame_entries(&blamed, compare_blame_suspect);
23882376
while (blamed)
23892377
{
23902378
struct blame_origin *porigin = blamed->suspect;

0 commit comments

Comments
 (0)