Message ID | 16932ced-8bcd-89bd-b927-cae1bce0365a@web.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/3] csum-file: add hashwrite_be64() | expand |
On 11/12/2020 7:20 AM, René Scharfe wrote: > Add a helper function for hashing and writing 64-bit integers in network > byte order. It returns the number of written bytes. This simplifies > callers that keep track of the file offset, even though this number is a > constant. > > Suggested-by: Derrick Stolee <dstolee@microsoft.com> > Original-patch-by: Taylor Blau <me@ttaylorr.com> These patches are absolutely correct, and I'm glad to see them show up in a very clear presentation. I had to go look to see why these were not already present, with [1] being the last instance of these showing up on-list. They did not get into the new version after a significant refactor [2]. Thanks, -Stolee [1] https://lore.kernel.org/git/20200904202226.GA21837@nand.local/ [2] https://lore.kernel.org/git/cover.1599664389.git.me@ttaylorr.com/
On Thu, Nov 12, 2020 at 08:52:24AM -0500, Derrick Stolee wrote: > On 11/12/2020 7:20 AM, René Scharfe wrote: > > Add a helper function for hashing and writing 64-bit integers in network > > byte order. It returns the number of written bytes. This simplifies > > callers that keep track of the file offset, even though this number is a > > constant. > > > > Suggested-by: Derrick Stolee <dstolee@microsoft.com> > > Original-patch-by: Taylor Blau <me@ttaylorr.com> > > These patches are absolutely correct, and I'm glad to see them show up > in a very clear presentation. I had to go look to see why these were > not already present, with [1] being the last instance of these showing > up on-list. They did not get into the new version after a significant > refactor [2]. That's right. What happened was we stopped writing the uncompressed "has an unpresentable Bloom filter" bitmap between the two versions you're talking about. Since we wrote each word as a big-endian 8-byte unsigned value, introducing hashwrite_be64() was useful in the earlier version. But in the rewritten version, there were no _new_ callers that would have wanted hashwrite_be64(), so I dropped those patches since the series was already large. That all being said, these are definitely useful patches to have, so I'm glad to see them being dug back up. Thanks, René :-). > Thanks, > -Stolee > > [1] https://lore.kernel.org/git/20200904202226.GA21837@nand.local/ > [2] https://lore.kernel.org/git/cover.1599664389.git.me@ttaylorr.com/ Thanks, Taylor
On Thu, Nov 12, 2020 at 01:20:19PM +0100, René Scharfe wrote: > Add a helper function for hashing and writing 64-bit integers in network > byte order. It returns the number of written bytes. This simplifies > callers that keep track of the file offset, even though this number is a > constant. > > Suggested-by: Derrick Stolee <dstolee@microsoft.com> > Original-patch-by: Taylor Blau <me@ttaylorr.com> > Signed-off-by: René Scharfe <l.s.r@web.de> > --- > csum-file.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/csum-file.h b/csum-file.h > index f9cbd317fb..e54d53d1d0 100644 > --- a/csum-file.h > +++ b/csum-file.h > @@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data) > hashwrite(f, &data, sizeof(data)); > } > > +static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) > +{ > + data = htonll(data); Great. This is new from my patch (which wrote the high- and low four bytes with two separate hashwrite_be32()'s), but I think it's a clear improvement. In addition to being more readable, we can use the bswap instruction once instead of twice if it exists. Please feel free to add my: Signed-off-by: Taylor Blau <me@ttaylorr.com> Thanks, Taylor
diff --git a/csum-file.h b/csum-file.h index f9cbd317fb..e54d53d1d0 100644 --- a/csum-file.h +++ b/csum-file.h @@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data) hashwrite(f, &data, sizeof(data)); } +static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) +{ + data = htonll(data); + hashwrite(f, &data, sizeof(data)); + return sizeof(data); +} + #endif
Add a helper function for hashing and writing 64-bit integers in network byte order. It returns the number of written bytes. This simplifies callers that keep track of the file offset, even though this number is a constant. Suggested-by: Derrick Stolee <dstolee@microsoft.com> Original-patch-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: René Scharfe <l.s.r@web.de> --- csum-file.h | 7 +++++++ 1 file changed, 7 insertions(+) -- 2.29.2