git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 08/10] fetch-pack: use DEFINE_LIST_SORT
Date: Sat, 16 Jul 2022 18:59:59 +0200	[thread overview]
Message-ID: <fcae44af-19c9-b289-9c2a-db726dbc586a@web.de> (raw)
In-Reply-To: <4d7cd286-398e-215c-f2bd-aa7e8207be4f@web.de>

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>
---
 fetch-pack.c |  8 ++++++++
 remote.c     | 22 ----------------------
 remote.h     |  2 --
 3 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/fetch-pack.c b/fetch-pack.c
index cb6647d657..e4503774b5 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -26,6 +26,7 @@
 #include "commit-reach.h"
 #include "commit-graph.h"
 #include "sigchain.h"
+#include "mergesort.h"

 static int transfer_unpack_limit = -1;
 static int fetch_unpack_limit = -1;
@@ -1025,6 +1026,13 @@ static int get_pack(struct fetch_pack_args *args,
 	return 0;
 }

+static int ref_compare_name(const struct ref *a, const struct ref *b)
+{
+	return strcmp(a->name, b->name);
+}
+
+DEFINE_LIST_SORT(static, sort_ref_list, struct ref, next);
+
 static int cmp_ref_by_name(const void *a_, const void *b_)
 {
 	const struct ref *a = *((const struct ref **)a_);
diff --git a/remote.c b/remote.c
index 1ee2b145d0..e90dca1d56 100644
--- a/remote.c
+++ b/remote.c
@@ -11,7 +11,6 @@
 #include "dir.h"
 #include "tag.h"
 #include "string-list.h"
-#include "mergesort.h"
 #include "strvec.h"
 #include "commit-reach.h"
 #include "advice.h"
@@ -1082,27 +1081,6 @@ void free_refs(struct ref *ref)
 	}
 }

-int ref_compare_name(const void *va, const void *vb)
-{
-	const struct ref *a = va, *b = vb;
-	return strcmp(a->name, b->name);
-}
-
-static void *ref_list_get_next(const void *a)
-{
-	return ((const struct ref *)a)->next;
-}
-
-static void ref_list_set_next(void *a, void *next)
-{
-	((struct ref *)a)->next = next;
-}
-
-void sort_ref_list(struct ref **l, int (*cmp)(const void *, const void *))
-{
-	*l = llist_mergesort(*l, ref_list_get_next, ref_list_set_next, cmp);
-}
-
 int count_refspec_match(const char *pattern,
 			struct ref *refs,
 			struct ref **matched_ref)
diff --git a/remote.h b/remote.h
index 448675e112..1c4621b414 100644
--- a/remote.h
+++ b/remote.h
@@ -207,9 +207,7 @@ struct ref *find_ref_by_name(const struct ref *list, const char *name);
 struct ref *alloc_ref(const char *name);
 struct ref *copy_ref(const struct ref *ref);
 struct ref *copy_ref_list(const struct ref *ref);
-void sort_ref_list(struct ref **, int (*cmp)(const void *, const void *));
 int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
-int ref_compare_name(const void *, const void *);

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

--
2.37.1

  parent reply	other threads:[~2022-07-16 17:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-16 16:50 [PATCH 00/10] typed sort of linked lists René Scharfe
2022-07-16 16:52 ` [PATCH 01/10] mergesort: unify ranks loops René Scharfe
2022-07-16 16:53 ` [PATCH 02/10] mergesort: tighten merge loop René Scharfe
2022-07-16 16:54 ` [PATCH 03/10] mergesort: add macros for typed sort of linked lists René Scharfe
2022-07-16 16:56 ` [PATCH 04/10] test-mergesort: use DEFINE_LIST_SORT_DEBUG René Scharfe
2022-07-16 16:57 ` [PATCH 05/10] test-mergesort: use DEFINE_LIST_SORT René Scharfe
2022-07-16 16:58 ` [PATCH 06/10] blame: " René Scharfe
2022-07-16 16:59 ` [PATCH 07/10] commit: " René Scharfe
2022-07-16 16:59 ` René Scharfe [this message]
2022-07-16 17:01 ` [PATCH 09/10] packfile: " René Scharfe
2022-07-16 17:02 ` [PATCH 10/10] mergesort: remove llist_mergesort() René Scharfe
2022-07-17 22:31 ` [PATCH 00/10] typed sort of linked lists Junio C Hamano
2022-07-25 18:52   ` Junio C Hamano
2022-07-25 20:35     ` Derrick Stolee
2022-07-25 20:49       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fcae44af-19c9-b289-9c2a-db726dbc586a@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).