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

index 0a3502603ffb752a51e569384984c05137c270e8..b5f63762824fa356d9a5f55f1cfc7959904d16fd 100644 (file)
@@ -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;
index 011852bef179191b867b96e9d0fb57b099bc60b3..1fc555e6728603136f3098fd8aa5f51338313dea 100644 (file)
@@ -173,6 +173,7 @@ struct bitmap {
 
 struct bitmap *bitmap_new(void);
 struct bitmap *bitmap_word_alloc(size_t word_alloc);
+struct bitmap *bitmap_dup(const struct bitmap *src);
 void bitmap_set(struct bitmap *self, size_t pos);
 void bitmap_unset(struct bitmap *self, size_t pos);
 int bitmap_get(struct bitmap *self, size_t pos);