midx.c: extract `midx_fanout_add_midx_fanout()`

Extract a routine to add all objects whose object ID's first byte is `cur_fanout` from an existing MIDX. This function will only be called once, so extracting it is purely cosmetic to improve the readability of `get_sorted_entries()` (its sole caller) below. The functionality is unchanged in this commit. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Aug 22, 2022 at 15:50 UTC 852c530102c5ca5b69ae863acaa1acb50cbba861
1 file changed +28 -19
midx.c
+28 -19
@@ -593,6 +593,31 @@ static void midx_fanout_sort(struct midx_fanout *fanout)
593 QSORT(fanout->entries, fanout->nr, midx_oid_compare);
594 }
595
596 +static void midx_fanout_add_midx_fanout(struct midx_fanout *fanout,
597 + struct multi_pack_index *m,
598 + int preferred_pack,
599 + uint32_t cur_fanout)
600 +{
601 + uint32_t start = 0, end;
602 + uint32_t cur_object;
603 +
604 + if (cur_fanout)
605 + start = ntohl(m->chunk_oid_fanout[cur_fanout - 1]);
606 + end = ntohl(m->chunk_oid_fanout[cur_fanout]);
607 +
608 + for (cur_object = start; cur_object < end; cur_object++) {
609 + midx_fanout_grow(fanout, fanout->nr + 1);
610 + nth_midxed_pack_midx_entry(m,
611 + &fanout->entries[fanout->nr],
612 + cur_object);
613 + if (nth_midxed_pack_int_id(m, cur_object) == preferred_pack)
614 + fanout->entries[fanout->nr].preferred = 1;
615 + else
616 + fanout->entries[fanout->nr].preferred = 0;
617 + fanout->nr++;
618 + }
619 +}
620 +
621 /*
622 * It is possible to artificially get into a state where there are many
623 * duplicate copies of objects. That can create high memory pressure if
@@ -633,25 +658,9 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
658 for (cur_fanout = 0; cur_fanout < 256; cur_fanout++) {
659 fanout.nr = 0;
660
636 - if (m) {
637 - uint32_t start = 0, end;
638 -
639 - if (cur_fanout)
640 - start = ntohl(m->chunk_oid_fanout[cur_fanout - 1]);
641 - end = ntohl(m->chunk_oid_fanout[cur_fanout]);
642 -
643 - for (cur_object = start; cur_object < end; cur_object++) {
644 - midx_fanout_grow(&fanout, fanout.nr + 1);
645 - nth_midxed_pack_midx_entry(m,
646 - &fanout.entries[fanout.nr],
647 - cur_object);
648 - if (nth_midxed_pack_int_id(m, cur_object) == preferred_pack)
649 - fanout.entries[fanout.nr].preferred = 1;
650 - else
651 - fanout.entries[fanout.nr].preferred = 0;
652 - fanout.nr++;
653 - }
654 - }
661 + if (m)
662 + midx_fanout_add_midx_fanout(&fanout, m, preferred_pack,
663 + cur_fanout);
664
665 for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
666 uint32_t start = 0, end;