Skip to content

Commit 2b5fe4d

Browse files
committed
remove an unneded allocation in roaring_bitmap_portable_serialize
Actually, in roaring_bitmap_portable_serialize. There's no need to allocate an array for the run container bitset, then copying into the destination buffer. Instead, write directly into the destination buffer.
1 parent 1b0e77a commit 2b5fe4d

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/roaring_array.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,14 @@ size_t ra_portable_serialize(const roaring_array_t *ra, char *buf) {
557557
memcpy(buf, &cookie, sizeof(cookie));
558558
buf += sizeof(cookie);
559559
uint32_t s = (ra->size + 7) / 8;
560-
uint8_t *bitmapOfRunContainers = (uint8_t *)roaring_calloc(s, 1);
561-
assert(bitmapOfRunContainers != NULL); // todo: handle
560+
memset(buf, 0, s);
562561
for (int32_t i = 0; i < ra->size; ++i) {
563562
if (get_container_type(ra->containers[i], ra->typecodes[i]) ==
564563
RUN_CONTAINER_TYPE) {
565-
bitmapOfRunContainers[i / 8] |= (1 << (i % 8));
564+
buf[i / 8] |= 1 << (i % 8);
566565
}
567566
}
568-
memcpy(buf, bitmapOfRunContainers, s);
569567
buf += s;
570-
roaring_free(bitmapOfRunContainers);
571568
if (ra->size < NO_OFFSET_THRESHOLD) {
572569
startOffset = 4 + 4 * ra->size + s;
573570
} else {

0 commit comments

Comments
 (0)