Skip to content

Commit 852c530

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 989d9cb commit 852c530

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

midx.c

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,31 @@ static void midx_fanout_sort(struct midx_fanout *fanout)
593593
QSORT(fanout->entries, fanout->nr, midx_oid_compare);
594594
}
595595

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+
596621
/*
597622
* It is possible to artificially get into a state where there are many
598623
* 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,
633658
for (cur_fanout = 0; cur_fanout < 256; cur_fanout++) {
634659
fanout.nr = 0;
635660

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);
655664

656665
for (cur_pack = start_pack; cur_pack < nr_packs; cur_pack++) {
657666
uint32_t start = 0, end;

0 commit comments

Comments
 (0)