diff options
author | Nicolas Pitre <nico@cam.org> | 2008-08-29 16:08:02 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-08-29 21:51:28 -0700 |
commit | d35825da6d5570524234e1bfe4ff0f57957b6db3 (patch) | |
tree | 1a02c65f37b000e5fae836fc8da11dc0d244fd20 /pack-write.c | |
parent | 8522148f79c29ef8f63688e7186e458a22333224 (diff) | |
download | git-d35825da6d5570524234e1bfe4ff0f57957b6db3.tar.gz git-d35825da6d5570524234e1bfe4ff0f57957b6db3.tar.xz |
fixup_pack_header_footer(): use nicely aligned buffer sizes
It should be more efficient to use nicely aligned buffer sizes, either
for filesystem operations or SHA1 checksums. Also, using a relatively
small nominal size might allow for the data to remain in L1 cache
between both SHA1_Update() calls.
Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack-write.c')
-rw-r--r-- | pack-write.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/pack-write.c b/pack-write.c index f9776c51f..939ed5636 100644 --- a/pack-write.c +++ b/pack-write.c @@ -167,7 +167,7 @@ void fixup_pack_header_footer(int pack_fd, unsigned char *partial_pack_sha1, off_t partial_pack_offset) { - static const int buf_sz = 128 * 1024; + int aligned_sz, buf_sz = 8 * 1024; SHA_CTX old_sha1_ctx, new_sha1_ctx; struct pack_header hdr; char *buf; @@ -188,10 +188,11 @@ void fixup_pack_header_footer(int pack_fd, partial_pack_offset -= sizeof(hdr); buf = xmalloc(buf_sz); + aligned_sz = buf_sz - sizeof(hdr); for (;;) { ssize_t m, n; - m = (partial_pack_sha1 && partial_pack_offset < buf_sz) ? - partial_pack_offset : buf_sz; + m = (partial_pack_sha1 && partial_pack_offset < aligned_sz) ? + partial_pack_offset : aligned_sz; n = xread(pack_fd, buf, m); if (!n) break; @@ -199,6 +200,10 @@ void fixup_pack_header_footer(int pack_fd, die("Failed to checksum %s: %s", pack_name, strerror(errno)); SHA1_Update(&new_sha1_ctx, buf, n); + aligned_sz -= n; + if (!aligned_sz) + aligned_sz = buf_sz; + if (!partial_pack_sha1) continue; |