{"thread":{"id":"54262","subject":"[PATCH] pack-write: use hashwrite_be32() in write_idx_file()","startedAt":"2020-09-19T18:37:03Z","lastAt":"2020-09-21T18:21:30Z","messageCount":2,"participants":["René Scharfe","Derrick Stolee"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"405946","messageId":"4c561e04-7edc-448f-46ca-4d4ac33e9ab3@web.de","threadId":"54262","inReplyTo":null,"subject":"[PATCH] pack-write: use hashwrite_be32() in write_idx_file()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-09-19T18:26:36Z","receivedAt":"2020-09-19T18:37:03Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Call hashwrite_be32() instead of open-coding it.  This shortens the code\na bit and makes it easier to read.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n pack-write.c | 12 ++++--------\n 1 file changed, 4 insertions(+), 8 deletions(-)\n\ndiff --git a/pack-write.c b/pack-write.c\nindex 685d327d80..a6cdb3c67c 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -117,10 +117,8 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \tlist = sorted_by_sha;\n \tfor (i = 0; i < nr_objects; i++) {\n \t\tstruct pack_idx_entry *obj = *list++;\n-\t\tif (index_version < 2) {\n-\t\t\tuint32_t offset = htonl(obj->offset);\n-\t\t\thashwrite(f, &offset, 4);\n-\t\t}\n+\t\tif (index_version < 2)\n+\t\t\thashwrite_be32(f, obj->offset);\n \t\thashwrite(f, obj->oid.hash, the_hash_algo->rawsz);\n \t\tif ((opts->flags & WRITE_IDX_STRICT) &&\n \t\t    (i && oideq(&list[-2]->oid, &obj->oid)))\n@@ -135,8 +133,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tlist = sorted_by_sha;\n \t\tfor (i = 0; i < nr_objects; i++) {\n \t\t\tstruct pack_idx_entry *obj = *list++;\n-\t\t\tuint32_t crc32_val = htonl(obj->crc32);\n-\t\t\thashwrite(f, &crc32_val, 4);\n+\t\t\thashwrite_be32(f, obj->crc32);\n \t\t}\n\n \t\t/* write the 32-bit offset table */\n@@ -148,8 +145,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\toffset = (need_large_offset(obj->offset, opts)\n \t\t\t\t  ? (0x80000000 | nr_large_offset++)\n \t\t\t\t  : obj->offset);\n-\t\t\toffset = htonl(offset);\n-\t\t\thashwrite(f, &offset, 4);\n+\t\t\thashwrite_be32(f, offset);\n \t\t}\n\n \t\t/* write the large offset table */\n--\n2.28.0\n"},{"id":"406063","messageId":"a074b239-95c0-3b95-338d-4b8b0c23d7da@gmail.com","threadId":"54262","inReplyTo":"4c561e04-7edc-448f-46ca-4d4ac33e9ab3@web.de","subject":"Re: [PATCH] pack-write: use hashwrite_be32() in write_idx_file()","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2020-09-21T18:21:28Z","receivedAt":"2020-09-21T18:21:30Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 9/19/2020 2:26 PM, René Scharfe wrote:\n> Call hashwrite_be32() instead of open-coding it.  This shortens the code\n> a bit and makes it easier to read.\n\nLGTM. Thanks!\n\n-Stolee\n"}]}