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: Jeff King <peff@peff.net>, Duy Nguyen <pclouds@gmail.com>
Cc: Junio C Hamano <gitster@pobox.com>,
	Git List <git@vger.kernel.org>,
	Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH] fast-export: avoid NULL pointer arithmetic
Date: Sat, 12 May 2018 10:49:36 +0200	[thread overview]
Message-ID: <01bb1946-df79-6448-663b-21a85cd44312@web.de> (raw)
In-Reply-To: <80397e16-8667-e0cd-4049-aad453d35e6f@web.de>

Am 12.05.2018 um 10:45 schrieb René Scharfe:
> Or we could roll our own custom hash map, as I mused in an earlier post.
> That would duplicate quite a bit of code; are there reusable pieces
> hidden within that could be extracted into common functions?

At least it would allow us to save four bytes of padding per object on
x64 by using a separate array for the hash map values; not sure how that
would impact performance, though.

---
 builtin/fast-export.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 627b0032f3..086fcaf9ea 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -72,13 +72,13 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt,
 
 struct object_mark_entry {
 	const struct object *base;
-	uint32_t mark;
 };
 
 struct object_marks {
 	unsigned int size;
 	unsigned int nr;
 	struct object_mark_entry *entries;
+	uint32_t *marks;
 };
 
 static struct object_marks idnums;
@@ -98,14 +98,14 @@ static void set_object_mark(struct object_marks *n, const struct object *base,
 
 	while (entries[j].base) {
 		if (entries[j].base == base) {
-			entries[j].mark = mark;
+			n->marks[j] = mark;
 			return;
 		}
 		if (++j >= size)
 			j = 0;
 	}
 	entries[j].base = base;
-	entries[j].mark = mark;
+	n->marks[j] = mark;
 	n->nr++;
 }
 
@@ -114,19 +114,22 @@ static void grow_object_marks(struct object_marks *n)
 	unsigned int i;
 	unsigned int old_size = n->size;
 	struct object_mark_entry *old_entries = n->entries;
+	uint32_t *old_marks = n->marks;
 
 	n->size = (old_size + 1000) * 3 / 2;
 	n->entries = xcalloc(n->size, sizeof(n->entries[0]));
+	n->marks = xcalloc(n->size, sizeof(n->marks[0]));
 	n->nr = 0;
 
 	for (i = 0; i < old_size; i++) {
 		const struct object *base = old_entries[i].base;
-		uint32_t mark = old_entries[i].mark;
+		uint32_t mark = old_marks[i];
 
 		if (mark)
 			set_object_mark(n, base, mark);
 	}
 	free(old_entries);
+	free(old_marks);
 }
 
 static int has_unshown_parent(struct commit *commit)
@@ -236,7 +239,7 @@ static int get_object_mark(struct object *object)
 	for (;;) {
 		struct object_mark_entry *ref = idnums.entries + j;
 		if (ref->base == object)
-			return ref->mark;
+			return idnums.marks[j];
 		if (!ref->base)
 			return 0;
 		if (++j == idnums.size)
@@ -966,7 +969,7 @@ static void export_marks(char *file)
 
 	for (i = 0; i < idnums.size; i++) {
 		if (entry->base && entry->base->type == 1) {
-			if (fprintf(f, ":%"PRIu32" %s\n", entry->mark,
+			if (fprintf(f, ":%"PRIu32" %s\n", idnums.marks[i],
 				    oid_to_hex(&entry->base->oid)) < 0) {
 			    e = 1;
 			    break;
-- 
2.17.0


  reply	other threads:[~2018-05-12  8:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09 21:06 [PATCH] fast-export: avoid NULL pointer arithmetic René Scharfe
2018-05-09 21:43 ` Johannes Schindelin
2018-05-10  9:24 ` René Scharfe
2018-05-10 10:51   ` Junio C Hamano
2018-05-10 19:47     ` René Scharfe
2018-05-11  2:16       ` Junio C Hamano
2018-05-11  4:49         ` Junio C Hamano
2018-05-11  6:19           ` Duy Nguyen
2018-05-11  8:56             ` Jeff King
2018-05-11 13:11               ` Duy Nguyen
2018-05-11 13:34                 ` Duy Nguyen
2018-05-11 17:42                   ` Jeff King
2018-05-12  8:45                     ` René Scharfe
2018-05-12  8:49                       ` René Scharfe [this message]
2018-05-14  1:37                       ` Junio C Hamano
2018-05-15 19:36                         ` René Scharfe

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=01bb1946-df79-6448-663b-21a85cd44312@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /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).