Skip to content

Commit be0d9d5

Browse files
pcloudsgitster
authored andcommitted
ewah: add convenient wrapper ewah_serialize_strbuf()
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27b099a commit be0d9d5

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

ewah/ewah_io.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#include "git-compat-util.h"
2121
#include "ewok.h"
22+
#include "strbuf.h"
2223

2324
int ewah_serialize_native(struct ewah_bitmap *self, int fd)
2425
{
@@ -110,6 +111,18 @@ int ewah_serialize(struct ewah_bitmap *self, int fd)
110111
return ewah_serialize_to(self, write_helper, (void *)(intptr_t)fd);
111112
}
112113

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+
113126
int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len)
114127
{
115128
const uint8_t *ptr = map;

ewah/ewok.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# define ewah_calloc xcalloc
3131
#endif
3232

33+
struct strbuf;
3334
typedef uint64_t eword_t;
3435
#define BITS_IN_WORD (sizeof(eword_t) * 8)
3536

@@ -98,6 +99,7 @@ int ewah_serialize_to(struct ewah_bitmap *self,
9899
void *out);
99100
int ewah_serialize(struct ewah_bitmap *self, int fd);
100101
int ewah_serialize_native(struct ewah_bitmap *self, int fd);
102+
int ewah_serialize_strbuf(struct ewah_bitmap *self, struct strbuf *);
101103

102104
int ewah_deserialize(struct ewah_bitmap *self, int fd);
103105
int ewah_read_mmap(struct ewah_bitmap *self, const void *map, size_t len);

split-index.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,15 @@ int read_link_extension(struct index_state *istate,
4141
return 0;
4242
}
4343

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-
5144
int write_link_extension(struct strbuf *sb,
5245
struct index_state *istate)
5346
{
5447
struct split_index *si = istate->split_index;
5548
strbuf_add(sb, si->base_sha1, 20);
5649
if (!si->delete_bitmap && !si->replace_bitmap)
5750
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);
6053
return 0;
6154
}
6255

0 commit comments

Comments
 (0)