From ccae08e822d71aaae1aa2660631d7ded8f4b97e7 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 8 Dec 2020 17:03:50 -0500 Subject: 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 Signed-off-by: Taylor Blau Signed-off-by: Junio C Hamano --- ewah/bitmap.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'ewah/bitmap.c') diff --git a/ewah/bitmap.c b/ewah/bitmap.c index 0a3502603f..b5f6376282 100644 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@ -35,6 +35,13 @@ struct bitmap *bitmap_new(void) return bitmap_word_alloc(32); } +struct bitmap *bitmap_dup(const struct bitmap *src) +{ + struct bitmap *dst = bitmap_word_alloc(src->word_alloc); + COPY_ARRAY(dst->words, src->words, src->word_alloc); + return dst; +} + static void bitmap_grow(struct bitmap *self, size_t word_alloc) { size_t old_size = self->word_alloc; -- cgit v1.3-5-g9baa