summaryrefslogtreecommitdiff
path: root/ewah
diff options
context:
space:
mode:
Diffstat (limited to 'ewah')
-rw-r--r--ewah/ewah_io.c17
-rw-r--r--ewah/ewok.h8
2 files changed, 20 insertions, 5 deletions
diff --git a/ewah/ewah_io.c b/ewah/ewah_io.c
index f7f700e..43481b9 100644
--- a/ewah/ewah_io.c
+++ b/ewah/ewah_io.c
@@ -19,6 +19,7 @@
*/
#include "git-compat-util.h"
#include "ewok.h"
+#include "strbuf.h"
int ewah_serialize_native(struct ewah_bitmap *self, int fd)
{
@@ -110,9 +111,21 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
}
-int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len)
+static int write_strbuf(void *user_data, const void *data, size_t len)
{
- uint8_t *ptr = map;
+ struct strbuf *sb = user_data;
+ strbuf_add(sb, data, len);
+ return len;
+}
+
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *sb)
+{
+ return ewah_serialize_to(self, write_strbuf, sb);
+}
+
+int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
+{
+ const uint8_t *ptr = map;
size_t i;
self->bit_size = get_be32(ptr);
diff --git a/ewah/ewok.h b/ewah/ewok.h
index 7e311b3..6e2c5e1 100644
--- a/ewah/ewok.h
+++ b/ewah/ewok.h
@@ -30,6 +30,7 @@
# define ewah_calloc xcalloc
#endif
+struct strbuf;
typedef uint64_t eword_t;
#define BITS_IN_EWORD (sizeof(eword_t) * 8)
@@ -47,7 +48,8 @@ static inline uint32_t ewah_bit_popcount64(uint64_t x)
return (x * 0x0101010101010101ULL) >> 56;
}
-#ifdef __GNUC__
+/* __builtin_ctzll was not available until 3.4.0 */
+#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR > 3))
#define ewah_bit_ctz64(x) __builtin_ctzll(x)
#else
static inline int ewah_bit_ctz64(uint64_t x)
@@ -97,10 +99,10 @@ int ewah_serialize_to(struct ewah_bitmap *self,
void *out);
int ewah_serialize(struct ewah_bitmap *self, int fd);
int ewah_serialize_native(struct ewah_bitmap *self, int fd);
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
int ewah_deserialize(struct ewah_bitmap *self, int fd);
-int ewah_read_mmap(struct ewah_bitmap *self, void *map, size_t len);
-int ewah_read_mmap_native(struct ewah_bitmap *self, void *map, size_t len);
+int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
uint32_t ewah_checksum(struct ewah_bitmap *self);