Skip to content

Commit d574bf4

Browse files
peffgitster
authored andcommitted
ewah: factor out bitmap growth
We auto-grow bitmaps when somebody asks to set a bit whose position is outside of our currently allocated range. Other operations besides single bit-setting might need to do this, too, so let's pull it into its own function. Note that we change the semantics a little: you now ask for the number of words you'd like to have, not the id of the block you'd like to write to. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2978b00 commit d574bf4

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

ewah/bitmap.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,22 @@ struct bitmap *bitmap_new(void)
3535
return bitmap_word_alloc(32);
3636
}
3737

38-
void bitmap_set(struct bitmap *self, size_t pos)
38+
static void bitmap_grow(struct bitmap *self, size_t word_alloc)
3939
{
40-
size_t block = EWAH_BLOCK(pos);
41-
42-
if (block >= self->word_alloc) {
40+
if (word_alloc > self->word_alloc) {
4341
size_t old_size = self->word_alloc;
44-
self->word_alloc = block ? block * 2 : 1;
42+
self->word_alloc = word_alloc * 2;
4543
REALLOC_ARRAY(self->words, self->word_alloc);
4644
memset(self->words + old_size, 0x0,
4745
(self->word_alloc - old_size) * sizeof(eword_t));
4846
}
47+
}
48+
49+
void bitmap_set(struct bitmap *self, size_t pos)
50+
{
51+
size_t block = EWAH_BLOCK(pos);
4952

53+
bitmap_grow(self, block + 1);
5054
self->words[block] |= EWAH_MASK(pos);
5155
}
5256

0 commit comments

Comments
 (0)