git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] midx: use hashwrite_be64()

From
René Scharfe <l.s.r@web.de>
Date
Nov 12, 2020, 12:22 UTC
Message-ID
<d38ac2a6-261c-4767-8691-8d97d551381c@web.de>
In-Reply-To
<16932ced-8bcd-89bd-b927-cae1bce0365a@web.de>

Call hashwrite_be64() to write 64-bit values instead of open-coding it using hashwrite_be32() and sizeof. This shortens the code and makes its intent clearer.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
And it saves me from headache induced by trying to remember whether "big
endian" means that the most significant ("big") digit comes first (yes)
or at the end, like the name suggests (no).
 midx.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/midx.c b/midx.c
index d233b54ac7..da03c1449a 100644
--- a/midx.c
+++ b/midx.c
@@ -785,9 +785,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
 		if (!(offset >> 31))
 			continue;

-		hashwrite_be32(f, offset >> 32);
-		hashwrite_be32(f, offset & 0xffffffffUL);
-		written += 2 * sizeof(uint32_t);
+		written += hashwrite_be64(f, offset);

 		nr_large_offset--;
 	}
@@ -975,8 +973,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 			    chunk_offsets[i]);

 		hashwrite_be32(f, chunk_ids[i]);
-		hashwrite_be32(f, chunk_offsets[i] >> 32);
-		hashwrite_be32(f, chunk_offsets[i]);
+		hashwrite_be64(f, chunk_offsets[i]);

 		written += MIDX_CHUNKLOOKUP_WIDTH;
 	}
--
2.29.2
Previous: René ScharfeNext: René Scharfe
Message 2 of 6 in “csum-file: add hashwrite_be64()”
  1. 1/3 csum-file: add hashwrite_be64()René Scharfe, Nov 12, 2020
  2. 2/3 midx: use hashwrite_be64()René Scharfe, Nov 12, 2020
  3. 3/3 pack-write: use hashwrite_be64()René Scharfe, Nov 12, 2020
  4. Derrick StoleeNov 12, 2020
  5. Taylor BlauNov 12, 2020
  6. Taylor BlauNov 12, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.