commit: use DEFINE_LIST_SORT
Use DEFINE_LIST_SORT to build a typed sort function for commit_list entries 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 18795 92 0 104654 123541 1e295 commit.o With this patch: __TEXT __DATA __OBJC others dec hex 18963 92 0 106094 125149 1e8dd commit.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:59 UTC
c0fb5774a6435a46931ec58ac27a5623efba9449
1 file changed
+6
-14
commit.c
+6
-14
@@ -631,10 +631,11 @@ struct commit_list * commit_list_insert_by_date(struct commit *item, struct comm
631
return commit_list_insert(item, pp);
632
}
633
634
-static int commit_list_compare_by_date(const void *a, const void *b)
634
+static int commit_list_compare_by_date(const struct commit_list *a,
635
+ const struct commit_list *b)
636
{
636
- timestamp_t a_date = ((const struct commit_list *)a)->item->date;
637
- timestamp_t b_date = ((const struct commit_list *)b)->item->date;
637
+ timestamp_t a_date = a->item->date;
638
+ timestamp_t b_date = b->item->date;
639
if (a_date < b_date)
640
return 1;
641
if (a_date > b_date)
@@ -642,20 +643,11 @@ static int commit_list_compare_by_date(const void *a, const void *b)
643
return 0;
644
}
645
645
-static void *commit_list_get_next(const void *a)
646
-{
647
- return ((const struct commit_list *)a)->next;
648
-}
649
-
650
-static void commit_list_set_next(void *a, void *next)
651
-{
652
- ((struct commit_list *)a)->next = next;
653
-}
646
+DEFINE_LIST_SORT(static, commit_list_sort, struct commit_list, next);
647
648
void commit_list_sort_by_date(struct commit_list **list)
649
{
657
- *list = llist_mergesort(*list, commit_list_get_next, commit_list_set_next,
658
- commit_list_compare_by_date);
650
+ commit_list_sort(list, commit_list_compare_by_date);
651
}
652
653
struct commit *pop_most_recent_commit(struct commit_list **list,