git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "René Scharfe" <l.s.r@web.de>, "Git Mailing List" <git@vger.kernel.org>
Subject: Re: [PATCH] pack-write: use hashwrite_be32() instead of double-buffering array
Date: Wed, 04 Nov 2020 08:23:22 -0800	[thread overview]
Message-ID: <xmqqmtzxnlad.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201104133653.GC3030480@coredump.intra.peff.net> (Jeff King's message of "Wed, 4 Nov 2020 08:36:53 -0500")

Jeff King <peff@peff.net> writes:

> On Sun, Nov 01, 2020 at 09:52:12AM +0100, René Scharfe wrote:
>
>> hashwrite() already buffers writes, so pass the fanout table entries
>> individually via hashwrite_be32(), which also does the endianess
>> conversion for us.  This avoids a memory copy, shortens the code and
>> reduces the number of magic numbers.
>
> Yep, this seems trivially correct. The key observation is that we are
> filling the array in order:
>
>> @@ -101,20 +100,19 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
>>  	for (i = 0; i < 256; i++) {
>>  		struct pack_idx_entry **next = list;
>>  		while (next < last) {
>>  			struct pack_idx_entry *obj = *next;
>>  			if (obj->oid.hash[0] != i)
>>  				break;
>>  			next++;
>>  		}
>> -		array[i] = htonl(next - sorted_by_sha);
>> +		hashwrite_be32(f, next - sorted_by_sha);
>>  		list = next;
>>  	}
>> -	hashwrite(f, array, 256 * 4);
>
> Perhaps obvious, but I got bit trying to do another similar conversion
> recently that was filling in the array out-of-order...

Yeah, filling an array out of order and then writing the result in
order would obviously different from writing out individual pieces
in the order the original codeflow used to fill the array.  Worse,
the order the data items are fed to hashwrite() obviously affects
the hash computed at the end.  An example of too much abstraction
biting us? ;-)



      reply	other threads:[~2020-11-04 16:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01  8:52 [PATCH] pack-write: use hashwrite_be32() instead of double-buffering array René Scharfe
2020-11-04 13:36 ` Jeff King
2020-11-04 16:23   ` Junio C Hamano [this message]

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=xmqqmtzxnlad.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --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).