# [PATCH] midx: use hashwrite_u8() in write_midx_header()

2 messages from 2020-09-06 to 2020-09-06. Participants: René Scharfe, Taylor Blau.
Thread: https://gitlist.dev/t/54197

## René Scharfe, 2020-09-06 08:59

Subject: [PATCH] midx: use hashwrite_u8() in write_midx_header()
Message-ID: <ae03833d-d597-f902-38d5-9e67bd768d93@web.de>
URL: https://gitlist.dev/e/ae03833d-d597-f902-38d5-9e67bd768d93%40web.de

```
Emit byte-sized values using hashwrite_u8() instead of buffering them
locally first.  The hashwrite functions already do their own buffering,
so this double-buffering does not reduce the number of system calls.
Getting rid of it shortens and simplifies the code a bit.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 midx.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/midx.c b/midx.c
index e9b2e1253a..6326ae17c6 100644
--- a/midx.c
+++ b/midx.c
@@ -428,14 +428,11 @@ static size_t write_midx_header(struct hashfile *f,
 				unsigned char num_chunks,
 				uint32_t num_packs)
 {
-	unsigned char byte_values[4];
-
 	hashwrite_be32(f, MIDX_SIGNATURE);
-	byte_values[0] = MIDX_VERSION;
-	byte_values[1] = oid_version();
-	byte_values[2] = num_chunks;
-	byte_values[3] = 0; /* unused */
-	hashwrite(f, byte_values, sizeof(byte_values));
+	hashwrite_u8(f, MIDX_VERSION);
+	hashwrite_u8(f, oid_version());
+	hashwrite_u8(f, num_chunks);
+	hashwrite_u8(f, 0); /* unused */
 	hashwrite_be32(f, num_packs);

 	return MIDX_HEADER_SIZE;
--
2.28.0

```

## Taylor Blau, 2020-09-06 19:03

Subject: Re: [PATCH] midx: use hashwrite_u8() in write_midx_header()
Message-ID: <20200906190340.GB6146@nand.local>
URL: https://gitlist.dev/e/20200906190340.GB6146%40nand.local
In-Reply-To: <ae03833d-d597-f902-38d5-9e67bd768d93@web.de>

```
On Sun, Sep 06, 2020 at 10:59:02AM +0200, René Scharfe wrote:
> Emit byte-sized values using hashwrite_u8() instead of buffering them
> locally first.  The hashwrite functions already do their own buffering,
> so this double-buffering does not reduce the number of system calls.
> Getting rid of it shortens and simplifies the code a bit.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>

Looks great.

  Acked-by: Taylor Blau <me@ttaylorr.com>

Thanks,
Taylor

```
