ewah: add convenient wrapper ewah_serialize_strbuf()
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Mar 8, 2015 at 17:12 UTC
be0d9d532326a81d761913e3ec9e2e7c62eeca7b
3 files changed
+17
-9
ewah/ewah_io.c
+13
@@ -19,6 +19,7 @@
19
*/
20
#include "git-compat-util.h"
21
#include "ewok.h"
22
+#include "strbuf.h"
23
24
int ewah_serialize_native(struct ewah_bitmap *self, int fd)
25
{
@@ -110,6 +111,18 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
111
return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
112
}
113
114
+static int write_strbuf(void *user_data, const void *data, size_t len)
115
+{
116
+ struct strbuf *sb = user_data;
117
+ strbuf_add(sb, data, len);
118
+ return len;
119
+}
120
+
121
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *sb)
122
+{
123
+ return ewah_serialize_to(self, write_strbuf, sb);
124
+}
125
+
126
int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
127
{
128
const uint8_t *ptr = map;
ewah/ewok.h
+2
@@ -30,6 +30,7 @@
30
# define ewah_calloc xcalloc
31
#endif
32
33
+struct strbuf;
34
typedef uint64_t eword_t;
35
#define BITS_IN_WORD (sizeof(eword_t) * 8)
36
@@ -98,6 +99,7 @@ int ewah_serialize_to(struct ewah_bitmap *self,
99
void *out);
100
int ewah_serialize(struct ewah_bitmap *self, int fd);
101
int ewah_serialize_native(struct ewah_bitmap *self, int fd);
102
+int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
103
104
int ewah_deserialize(struct ewah_bitmap *self, int fd);
105
int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);
split-index.c
+2
-9
@@ -41,13 +41,6 @@ int read_link_extension(struct index_state *istate,
41
return 0;
42
}
43
44
-static int write_strbuf(void *user_data, const void *data, size_t len)
45
-{
46
- struct strbuf *sb = user_data;
47
- strbuf_add(sb, data, len);
48
- return len;
49
-}
50
-
44
int write_link_extension(struct strbuf *sb,
45
struct index_state *istate)
46
{
@@ -55,8 +48,8 @@ int write_link_extension(struct strbuf *sb,
48
strbuf_add(sb, si->base_sha1, 20);
49
if (!si->delete_bitmap && !si->replace_bitmap)
50
return 0;
58
- ewah_serialize_to(si->delete_bitmap, write_strbuf, sb);
59
- ewah_serialize_to(si->replace_bitmap, write_strbuf, sb);
51
+ ewah_serialize_strbuf(si->delete_bitmap, sb);
52
+ ewah_serialize_strbuf(si->replace_bitmap, sb);
53
return 0;
54
}
55