diff options
author | Jeff King <peff@peff.net> | 2020-02-23 23:36:31 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-02-24 12:55:53 -0800 |
commit | 63f4a7fc0107ec240f48605a4d4f8e41b91caa41 (patch) | |
tree | a20801bdaaeda04f522eab0fb571ca8c693e01b5 /walker.c | |
parent | pack-check: convert "internal error" die to a BUG() (diff) | |
download | tgif-63f4a7fc0107ec240f48605a4d4f8e41b91caa41.tar.xz |
pack-check: push oid lookup into loop
When we're checking a pack with fsck or verify-pack, we first sort the
idx entries by offset, since accessing them in pack order is more
efficient. To do so, we loop over them and fill in an array of structs
with the offset, object_id, and index position of each, sort the result,
and only then do we iterate over the sorted array and process each
entry.
In order to avoid the memory cost of storing the hash of each object, we
just store a pointer into the copy in the mmap'd pack index file. To
keep that property even as the rest of the code converted to "struct
object_id", commit 9fd750461b (Convert the verify_pack callback to
struct object_id, 2017-05-06) introduced a union in order to type-pun
the pointer-to-hash into an object_id struct.
But we can make this even simpler by observing that the sort operation
doesn't need the object id at all! We only need them one at a time while
we actually process each entry. So we can just omit the oid from the
struct entirely and load it on the fly into a local variable in the
second loop.
This gets rid of the type-punning, and lets us directly use the more
type-safe nth_packed_object_id(), simplifying the code. And as a bonus,
it saves 8 bytes of memory per object.
Note that this does mean we'll do the offset lookup for each object
before the oid lookup. The oid lookup has more safety checks in it
(e.g., for looking past p->num_objects) which in theory protected the
offset lookup. But since violating those checks was already a BUG()
condition (as described in the previous commit), it's not worth worrying
about.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'walker.c')
0 files changed, 0 insertions, 0 deletions