commit 976846014daddf292e080f2857ae63173f7b1433 from: Stefan Sperling date: Wed Mar 18 16:13:46 2020 UTC write CRC info in one chunk rather than calling write(2) once per object commit - 021b0c6fb25d296a1463498da56435aee399dfe9 commit + 976846014daddf292e080f2857ae63173f7b1433 blob - eaf56a186124e48676c6d3d45068d94d1a8970e7 blob + 6d9aba3a2c465cbd5214ad2a5a407faabacde49a --- libexec/got-index-pack/got-index-pack.c +++ libexec/got-index-pack/got-index-pack.c @@ -476,6 +476,7 @@ add_indexed_object(struct got_packidx *packidx, uint32 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 *tmp 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"); @@ -794,6 +800,9 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp goto done; make_packidx(&packidx, nobj, objects); + + free(objects); + objects = NULL; SHA1Init(&ctx); putbe32(buf, GOT_PACKIDX_V2_MAGIC); @@ -809,12 +818,9 @@ index_pack(struct got_pack *pack, int idxfd, FILE *tmp 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)