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>
Nicolas Pitre committed
Aug 29, 2008 at 16:08 UTC
d35825da6d5570524234e1bfe4ff0f57957b6db3
1 file changed
+8
-3
pack-write.c
+8
-3
@@ -167,7 +167,7 @@ void fixup_pack_header_footer(int pack_fd,
167
unsigned char *partial_pack_sha1,
168
off_t partial_pack_offset)
169
{
170
- static const int buf_sz = 128 * 1024;
170
+ int aligned_sz, buf_sz = 8 * 1024;
171
SHA_CTX old_sha1_ctx, new_sha1_ctx;
172
struct pack_header hdr;
173
char *buf;
@@ -188,10 +188,11 @@ void fixup_pack_header_footer(int pack_fd,
188
partial_pack_offset -= sizeof(hdr);
189
190
buf = xmalloc(buf_sz);
191
+ aligned_sz = buf_sz - sizeof(hdr);
192
for (;;) {
193
ssize_t m, n;
193
- m = (partial_pack_sha1 && partial_pack_offset < buf_sz) ?
194
- partial_pack_offset : buf_sz;
194
+ m = (partial_pack_sha1 && partial_pack_offset < aligned_sz) ?
195
+ partial_pack_offset : aligned_sz;
196
n = xread(pack_fd, buf, m);
197
if (!n)
198
break;
@@ -199,6 +200,10 @@ void fixup_pack_header_footer(int pack_fd,
200
die("Failed to checksum %s: %s", pack_name, strerror(errno));
201
SHA1_Update(&new_sha1_ctx, buf, n);
202
203
+ aligned_sz -= n;
204
+ if (!aligned_sz)
205
+ aligned_sz = buf_sz;
206
+
207
if (!partial_pack_sha1)
208
continue;
209