]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-write: use hashwrite_be32() instead of double-buffering array
authorRené Scharfe <l.s.r@web.de>
Sun, 1 Nov 2020 08:52:12 +0000 (09:52 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 1 Nov 2020 23:52:51 +0000 (15:52 -0800)
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.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
pack-write.c

index a6cdb3c67ccac3a0cb273d4e4d24bd35ac2b4bf4..23e19cc1ecb2ed43f2559e45541f24c76ccde6f6 100644 (file)
@@ -48,7 +48,6 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
        struct hashfile *f;
        struct pack_idx_entry **sorted_by_sha, **list, **last;
        off_t last_obj_offset = 0;
-       uint32_t array[256];
        int i, fd;
        uint32_t index_version;
 
@@ -106,10 +105,9 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
                                break;
                        next++;
                }
-               array[i] = htonl(next - sorted_by_sha);
+               hashwrite_be32(f, next - sorted_by_sha);
                list = next;
        }
-       hashwrite(f, array, 256 * 4);
 
        /*
         * Write the actual SHA1 entries..