Skip to content

Commit ccae08e

Browse files
peffgitster
authored andcommitted
ewah: add bitmap_dup() function
There's no easy way to make a copy of a bitmap. Obviously a caller can iterate over the bits and set them one by one in a new bitmap, but we can go much faster by copying whole words with memcpy(). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ed6751 commit ccae08e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

ewah/bitmap.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ struct bitmap *bitmap_new(void)
3535
return bitmap_word_alloc(32);
3636
}
3737

38+
struct bitmap *bitmap_dup(const struct bitmap *src)
39+
{
40+
struct bitmap *dst = bitmap_word_alloc(src->word_alloc);
41+
COPY_ARRAY(dst->words, src->words, src->word_alloc);
42+
return dst;
43+
}
44+
3845
static void bitmap_grow(struct bitmap *self, size_t word_alloc)
3946
{
4047
size_t old_size = self->word_alloc;

ewah/ewok.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct bitmap {
173173

174174
struct bitmap *bitmap_new(void);
175175
struct bitmap *bitmap_word_alloc(size_t word_alloc);
176+
struct bitmap *bitmap_dup(const struct bitmap *src);
176177
void bitmap_set(struct bitmap *self, size_t pos);
177178
void bitmap_unset(struct bitmap *self, size_t pos);
178179
int bitmap_get(struct bitmap *self, size_t pos);

0 commit comments

Comments
 (0)