Re: [PATCH 09/20] try_partial_reuse(): convert to new revindex API
- From
Jeff King <peff@peff.net>
- Date
- Jan 12, 2021, 09:06 UTC
- Message-ID
- <X/1mpl/ZmL4NPIEm@coredump.intra.peff.net>
- In-Reply-To
- <54f4ad329f56808432549aa885f2847d5c9a8ac6.1610129796.git.me@ttaylorr.com>
On Fri, Jan 08, 2021 at 01:17:17PM -0500, Taylor Blau wrote:
Show 13 quoted lines
> Remove another instance of direct revindex manipulation by calling > 'pack_pos_to_offset()' instead (the caller here does not care about the > index position of the object at position 'pos'). > > Somewhat confusingly, the subsequent call to unpack_object_header() > takes a pointer to &offset and then updates it with a new value. But, > try_partial_reuse() cares about the offset of both the base's header and > contents. The existing code made a copy of the offset field, and only > addresses and manipulates one of them. > > Instead, store the return of pack_pos_to_offset twice: once in header > and another in offset. Header will be left untouched, but offset will be > addressed and modified by unpack_object_header().
I had to read these second two paragraphs a few times to parse them. Really we are just replacing revidx->offset with "header", and "offset" retains its same role within the function.
So it's definitely doing the right thing, but it makes more sense to me as:
Note that we cannot just use the existing "offset" variable to store
the value we get from pack_pos_to_offset(). It is incremented by
unpack_object_header(), but we later need the original value. Since
we'll no longer have revindex->offset to read it from, we'll store
that in a separate variable ("header" since it points to the entry's
header bytes).Another option would be to just call pack_pos_to_offset() again for the later call. Like the code it's replacing, it's constant-time anyway. But I think the "header" variable actually makes things more readable.
-Peff