fetch-pack: use DEFINE_LIST_SORT

Build a static typed ref sorting function using DEFINE_LIST_SORT along with a typed comparison function near its only two callers instead of having an exported version that calls 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 23231 389 0 113689 137309 2185d fetch-pack.o 29158 80 0 146864 176102 2afe6 remote.o With this patch: __TEXT __DATA __OBJC others dec hex 23591 389 0 117759 141739 229ab fetch-pack.o 29070 80 0 145718 174868 2ab14 remote.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 6fc9fec07bcaa6561aff5b485f1ac581f97a2428
3 files changed +8 -24
fetch-pack.c
+8
@@ -26,6 +26,7 @@
26 #include "commit-reach.h"
27 #include "commit-graph.h"
28 #include "sigchain.h"
29 +#include "mergesort.h"
30
31 static int transfer_unpack_limit = -1;
32 static int fetch_unpack_limit = -1;
@@ -1010,6 +1011,13 @@ static int get_pack(struct fetch_pack_args *args,
1011 return 0;
1012 }
1013
1014 +static int ref_compare_name(const struct ref *a, const struct ref *b)
1015 +{
1016 + return strcmp(a->name, b->name);
1017 +}
1018 +
1019 +DEFINE_LIST_SORT(static, sort_ref_list, struct ref, next);
1020 +
1021 static int cmp_ref_by_name(const void *a_, const void *b_)
1022 {
1023 const struct ref *a = *((const struct ref **)a_);
remote.c
-22
@@ -10,7 +10,6 @@
10 #include "dir.h"
11 #include "tag.h"
12 #include "string-list.h"
13 -#include "mergesort.h"
13 #include "strvec.h"
14 #include "commit-reach.h"
15 #include "advice.h"
@@ -1031,27 +1030,6 @@ void free_refs(struct ref *ref)
1030 }
1031 }
1032
1034 -int ref_compare_name(const void *va, const void *vb)
1035 -{
1036 - const struct ref *a = va, *b = vb;
1037 - return strcmp(a->name, b->name);
1038 -}
1039 -
1040 -static void *ref_list_get_next(const void *a)
1041 -{
1042 - return ((const struct ref *)a)->next;
1043 -}
1044 -
1045 -static void ref_list_set_next(void *a, void *next)
1046 -{
1047 - ((struct ref *)a)->next = next;
1048 -}
1049 -
1050 -void sort_ref_list(struct ref **l, int (*cmp)(const void *, const void *))
1051 -{
1052 - *l = llist_mergesort(*l, ref_list_get_next, ref_list_set_next, cmp);
1053 -}
1054 -
1033 int count_refspec_match(const char *pattern,
1034 struct ref *refs,
1035 struct ref **matched_ref)
remote.h
-2
@@ -207,9 +207,7 @@ struct ref *find_ref_by_name(const struct ref *list, const char *name);
207 struct ref *alloc_ref(const char *name);
208 struct ref *copy_ref(const struct ref *ref);
209 struct ref *copy_ref_list(const struct ref *ref);
210 -void sort_ref_list(struct ref **, int (*cmp)(const void *, const void *));
210 int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
212 -int ref_compare_name(const void *, const void *);
211
212 int check_ref_type(const struct ref *ref, int flags);
213