Skip to content

Commit 6fc9fec

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c0fb577 commit 6fc9fec

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

fetch-pack.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "commit-reach.h"
2727
#include "commit-graph.h"
2828
#include "sigchain.h"
29+
#include "mergesort.h"
2930

3031
static int transfer_unpack_limit = -1;
3132
static int fetch_unpack_limit = -1;
@@ -1010,6 +1011,13 @@ static int get_pack(struct fetch_pack_args *args,
10101011
return 0;
10111012
}
10121013

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+
10131021
static int cmp_ref_by_name(const void *a_, const void *b_)
10141022
{
10151023
const struct ref *a = *((const struct ref **)a_);

remote.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "dir.h"
1111
#include "tag.h"
1212
#include "string-list.h"
13-
#include "mergesort.h"
1413
#include "strvec.h"
1514
#include "commit-reach.h"
1615
#include "advice.h"
@@ -1031,27 +1030,6 @@ void free_refs(struct ref *ref)
10311030
}
10321031
}
10331032

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-
10551033
int count_refspec_match(const char *pattern,
10561034
struct ref *refs,
10571035
struct ref **matched_ref)

remote.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ struct ref *find_ref_by_name(const struct ref *list, const char *name);
207207
struct ref *alloc_ref(const char *name);
208208
struct ref *copy_ref(const struct ref *ref);
209209
struct ref *copy_ref_list(const struct ref *ref);
210-
void sort_ref_list(struct ref **, int (*cmp)(const void *, const void *));
211210
int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
212-
int ref_compare_name(const void *, const void *);
213211

214212
int check_ref_type(const struct ref *ref, int flags);
215213

0 commit comments

Comments
 (0)