write CRC info in one chunk rather than calling write(2) once per object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/libexec/got-index-pack/got-index-pack.c b/libexec/got-index-pack/got-index-pack.c
index eaf56a1..6d9aba3 100644
--- a/libexec/got-index-pack/got-index-pack.c
+++ b/libexec/got-index-pack/got-index-pack.c
@@ -476,6 +476,7 @@ add_indexed_object(struct got_packidx *packidx, uint32_t idx,
memcpy(packidx->hdr.sorted_ids[idx].sha1, obj->id.sha1,
SHA1_DIGEST_LENGTH);
+ packidx->hdr.crc32[idx] = htobe32(obj->crc);
if (obj->off < GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX)
packidx->hdr.offsets[idx] = htobe32(obj->off);
else {
@@ -621,6 +622,11 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
err = got_error_from_errno("calloc");
goto done;
}
+ packidx.hdr.crc32 = calloc(nobj, sizeof(uint32_t));
+ if (packidx.hdr.crc32 == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
packidx.hdr.offsets = calloc(nobj, sizeof(uint32_t));
if (packidx.hdr.offsets == NULL) {
err = got_error_from_errno("calloc");
@@ -795,6 +801,9 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
make_packidx(&packidx, nobj, objects);
+ free(objects);
+ objects = NULL;
+
SHA1Init(&ctx);
putbe32(buf, GOT_PACKIDX_V2_MAGIC);
putbe32(buf + 4, GOT_PACKIDX_VERSION);
@@ -809,12 +818,9 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmpfile,
nobj * SHA1_DIGEST_LENGTH, &ctx);
if (err)
goto done;
- for(i = 0; i < nobj; i++){
- putbe32(buf, objects[i].crc);
- err = hwrite(idxfd, buf, 4, &ctx);
- if (err)
- goto done;
- }
+ err = hwrite(idxfd, packidx.hdr.crc32, nobj * sizeof(uint32_t), &ctx);
+ if (err)
+ goto done;
err = hwrite(idxfd, packidx.hdr.offsets, nobj * sizeof(uint32_t),
&ctx);
if (err)