]> git.ipfire.org Git - thirdparty/git.git/commitdiff
ewah: factor out bitmap growth
authorJeff King <peff@peff.net>
Tue, 8 Dec 2020 22:03:38 +0000 (17:03 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Dec 2020 22:48:16 +0000 (14:48 -0800)
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 <peff@peff.net>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ewah/bitmap.c

index d8cec585af97e66e0534c1cebd32f2cdf022d382..7c1ecfa6fd1198034f7d0a5d6b0fb847a2450028 100644 (file)
@@ -35,18 +35,22 @@ struct bitmap *bitmap_new(void)
        return bitmap_word_alloc(32);
 }
 
-void bitmap_set(struct bitmap *self, size_t pos)
+static void bitmap_grow(struct bitmap *self, size_t word_alloc)
 {
-       size_t block = EWAH_BLOCK(pos);
-
-       if (block >= self->word_alloc) {
+       if (word_alloc > self->word_alloc) {
                size_t old_size = self->word_alloc;
-               self->word_alloc = block ? block * 2 : 1;
+               self->word_alloc = word_alloc * 2;
                REALLOC_ARRAY(self->words, self->word_alloc);
                memset(self->words + old_size, 0x0,
                        (self->word_alloc - old_size) * sizeof(eword_t));
        }
+}
+
+void bitmap_set(struct bitmap *self, size_t pos)
+{
+       size_t block = EWAH_BLOCK(pos);
 
+       bitmap_grow(self, block + 1);
        self->words[block] |= EWAH_MASK(pos);
 }