midx.c: improve cache locality in midx_pack_order_cmp()
authorJeff King <peff@peff.net>
Tue, 30 Mar 2021 15:04:36 +0000 (11:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 1 Apr 2021 20:07:37 +0000 (13:07 -0700)
commit30077524611cae8f25111e2c8b8d42136aa58787
tree3f2baaf6817d22018f5d999dd3e70f37d2de57a2
parent38ff7cabb6b8e51df78ce20c20632eba24265ee4
midx.c: improve cache locality in midx_pack_order_cmp()

There is a lot of pointer dereferencing in the pre-image version of
'midx_pack_order_cmp()', which this patch gets rid of.

Instead of comparing the pack preferred-ness and then the pack id, both
of these checks are done at the same time by using the high-order bit of
the pack id to represent whether it's preferred. Then the pack id and
offset are compared as usual.

This produces the same result so long as there are less than 2^31 packs,
which seems like a likely assumption to make in practice.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
midx.c