Skip to content

Commit

Permalink
pack-bitmap.c: use ewah_or_iterator for type bitmap iterators
Browse files Browse the repository at this point in the history
Now that we have initialized arrays for each bitmap layer's type bitmaps
in the previous commit, adjust existing callers to use them in
preparation for multi-layered bitmaps.

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr committed Nov 19, 2024
1 parent 9ab8fb4 commit 87cb011
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,25 +1622,29 @@ static void show_extended_objects(struct bitmap_index *bitmap_git,
}
}

static void init_type_iterator(struct ewah_iterator *it,
static void init_type_iterator(struct ewah_or_iterator *it,
struct bitmap_index *bitmap_git,
enum object_type type)
{
switch (type) {
case OBJ_COMMIT:
ewah_iterator_init(it, bitmap_git->commits);
ewah_or_iterator_init(it, bitmap_git->commits_all,
bitmap_git->base_nr);
break;

case OBJ_TREE:
ewah_iterator_init(it, bitmap_git->trees);
ewah_or_iterator_init(it, bitmap_git->trees_all,
bitmap_git->base_nr);
break;

case OBJ_BLOB:
ewah_iterator_init(it, bitmap_git->blobs);
ewah_or_iterator_init(it, bitmap_git->blobs_all,
bitmap_git->base_nr);
break;

case OBJ_TAG:
ewah_iterator_init(it, bitmap_git->tags);
ewah_or_iterator_init(it, bitmap_git->tags_all,
bitmap_git->base_nr);
break;

default:
Expand All @@ -1657,15 +1661,15 @@ static void show_objects_for_type(
size_t i = 0;
uint32_t offset;

struct ewah_iterator it;
struct ewah_or_iterator it;
eword_t filter;

struct bitmap *objects = bitmap_git->result;

init_type_iterator(&it, bitmap_git, object_type);

for (i = 0; i < objects->word_alloc &&
ewah_iterator_next(&filter, &it); i++) {
ewah_or_iterator_next(&filter, &it); i++) {
eword_t word = objects->words[i] & filter;
size_t pos = (i * BITS_IN_EWORD);

Expand Down Expand Up @@ -1707,6 +1711,8 @@ static void show_objects_for_type(
show_reach(&oid, object_type, 0, hash, pack, ofs);
}
}

ewah_or_iterator_free(&it);
}

static int in_bitmapped_pack(struct bitmap_index *bitmap_git,
Expand Down Expand Up @@ -1758,7 +1764,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
{
struct eindex *eindex = &bitmap_git->ext_index;
struct bitmap *tips;
struct ewah_iterator it;
struct ewah_or_iterator it;
eword_t mask;
uint32_t i;

Expand All @@ -1775,7 +1781,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
* packfile.
*/
for (i = 0, init_type_iterator(&it, bitmap_git, type);
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
i < to_filter->word_alloc && ewah_or_iterator_next(&mask, &it);
i++) {
if (i < tips->word_alloc)
mask &= ~tips->words[i];
Expand All @@ -1795,6 +1801,7 @@ static void filter_bitmap_exclude_type(struct bitmap_index *bitmap_git,
bitmap_unset(to_filter, pos);
}

ewah_or_iterator_free(&it);
bitmap_free(tips);
}

Expand Down Expand Up @@ -1852,14 +1859,14 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
{
struct eindex *eindex = &bitmap_git->ext_index;
struct bitmap *tips;
struct ewah_iterator it;
struct ewah_or_iterator it;
eword_t mask;
uint32_t i;

tips = find_tip_objects(bitmap_git, tip_objects, OBJ_BLOB);

for (i = 0, init_type_iterator(&it, bitmap_git, OBJ_BLOB);
i < to_filter->word_alloc && ewah_iterator_next(&mask, &it);
i < to_filter->word_alloc && ewah_or_iterator_next(&mask, &it);
i++) {
eword_t word = to_filter->words[i] & mask;
unsigned offset;
Expand Down Expand Up @@ -1887,6 +1894,7 @@ static void filter_bitmap_blob_limit(struct bitmap_index *bitmap_git,
bitmap_unset(to_filter, pos);
}

ewah_or_iterator_free(&it);
bitmap_free(tips);
}

Expand Down Expand Up @@ -2506,12 +2514,12 @@ static uint32_t count_object_type(struct bitmap_index *bitmap_git,
struct eindex *eindex = &bitmap_git->ext_index;

uint32_t i = 0, count = 0;
struct ewah_iterator it;
struct ewah_or_iterator it;
eword_t filter;

init_type_iterator(&it, bitmap_git, type);

while (i < objects->word_alloc && ewah_iterator_next(&filter, &it)) {
while (i < objects->word_alloc && ewah_or_iterator_next(&filter, &it)) {
eword_t word = objects->words[i++] & filter;
count += ewah_bit_popcount64(word);
}
Expand All @@ -2523,6 +2531,8 @@ static uint32_t count_object_type(struct bitmap_index *bitmap_git,
count++;
}

ewah_or_iterator_free(&it);

return count;
}

Expand Down Expand Up @@ -3051,13 +3061,13 @@ static off_t get_disk_usage_for_type(struct bitmap_index *bitmap_git,
{
struct bitmap *result = bitmap_git->result;
off_t total = 0;
struct ewah_iterator it;
struct ewah_or_iterator it;
eword_t filter;
size_t i;

init_type_iterator(&it, bitmap_git, object_type);
for (i = 0; i < result->word_alloc &&
ewah_iterator_next(&filter, &it); i++) {
ewah_or_iterator_next(&filter, &it); i++) {
eword_t word = result->words[i] & filter;
size_t base = (i * BITS_IN_EWORD);
unsigned offset;
Expand Down Expand Up @@ -3098,6 +3108,8 @@ static off_t get_disk_usage_for_type(struct bitmap_index *bitmap_git,
}
}

ewah_or_iterator_free(&it);

return total;
}

Expand Down

0 comments on commit 87cb011

Please sign in to comment.