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 <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jul 16, 2022 at 18:58 UTC
47c30f7daa0858953043cdd2f9dfec75aeb0759d
1 file changed
+9
-21
blame.c
+9
-21
@@ -1098,30 +1098,22 @@ static struct blame_entry *blame_merge(struct blame_entry *list1,
1098
}
1099
}
1100
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);
1102
1103
/*
1104
* Final image line numbers are all different, so we don't need a
1105
* three-way comparison here.
1106
*/
1107
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)
1110
{
1118
- return ((struct blame_entry *)p1)->lno > ((struct blame_entry *)p2)->lno
1119
- ? 1 : -1;
1111
+ return e1->lno > e2->lno ? 1 : -1;
1112
}
1113
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)
1116
{
1124
- const struct blame_entry *s1 = p1, *s2 = p2;
1117
/*
1118
* to allow for collating suspects, we sort according to the
1119
* respective pointer value as the primary sorting criterion.
@@ -1138,8 +1130,7 @@ static int compare_blame_suspect(const void *p1, const void *p2)
1130
1131
void blame_sort_final(struct blame_scoreboard *sb)
1132
{
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);
1134
}
1135
1136
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,
1955
parent, target, 0);
1956
*d.dstq = NULL;
1957
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);
1959
queue_blames(sb, parent, newdest);
1960
1961
return;
@@ -2383,8 +2372,7 @@ static int num_scapegoats(struct rev_info *revs, struct commit *commit, int reve
2372
*/
2373
static void distribute_blame(struct blame_scoreboard *sb, struct blame_entry *blamed)
2374
{
2386
- blamed = llist_mergesort(blamed, get_next_blame, set_next_blame,
2387
- compare_blame_suspect);
2375
+ sort_blame_entries(&blamed, compare_blame_suspect);
2376
while (blamed)
2377
{
2378
struct blame_origin *porigin = blamed->suspect;