Re: [PATCH] pack-write: use hashwrite_be32() instead of double-buffering array
- From
Jeff King <peff@peff.net>
- Date
- Nov 4, 2020, 13:36 UTC
- Message-ID
- <20201104133653.GC3030480@coredump.intra.peff.net>
- In-Reply-To
- <aec69531-d621-ab26-efd4-96e1ae0ed3a4@web.de>
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:
Show 14 quoted lines
> @@ -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 (not on the list, but in some improvements in the bitmap code that haven't been sent in yet).
-Peff