Skip to content

Commit

Permalink
mp: use referenced values when composing CFL object
Browse files Browse the repository at this point in the history
When creating a CFL object from a MessagePack buffer, now the strings and bytes
data types are created as references, that means we don't copy the data to the
new buffer.

This change has been made for performance reasons by using the updated CFL
library v0.5.0.

Signed-off-by: Eduardo Silva <[email protected]>
  • Loading branch information
edsiper committed Apr 18, 2024
1 parent bf4cb71 commit 1ce8d04
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/flb_mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ static int mp_object_to_cfl(void **ptr, msgpack_object *o)
break;
case MSGPACK_OBJECT_STR:
var = cfl_variant_create_from_string_s((char *) o->via.str.ptr,
o->via.str.size);
o->via.str.size, CFL_TRUE);
if (!var) {
return -1;
}
Expand All @@ -766,7 +766,7 @@ static int mp_object_to_cfl(void **ptr, msgpack_object *o)
break;
case MSGPACK_OBJECT_BIN:
var = cfl_variant_create_from_bytes((char *) o->via.str.ptr,
o->via.str.size);
o->via.str.size, CFL_TRUE);
if (!var) {
return -1;
}
Expand Down Expand Up @@ -945,17 +945,17 @@ static int mp_cfl_to_msgpack(struct cfl_variant *var,
/* we don't save references */
break;
case CFL_VARIANT_STRING:
msgpack_pack_str(mp_pck, cfl_sds_len(var->data.as_string));
msgpack_pack_str(mp_pck, cfl_variant_size_get(var));
msgpack_pack_str_body(mp_pck,
var->data.as_string, cfl_sds_len(var->data.as_string));
var->data.as_string, cfl_variant_size_get(var));
break;
case CFL_VARIANT_BYTES:
msgpack_pack_bin(mp_pck, cfl_sds_len(var->data.as_bytes));
msgpack_pack_bin(mp_pck, cfl_variant_size_get(var));
msgpack_pack_bin_body(mp_pck,
var->data.as_bytes, cfl_sds_len(var->data.as_bytes));
var->data.as_bytes, cfl_variant_size_get(var));
break;
case CFL_VARIANT_ARRAY:
msgpack_pack_array(mp_pck, var->data.as_array->entry_count);
msgpack_pack_array(mp_pck, var->data.as_array->entry_count);
for (i = 0; i < var->data.as_array->entry_count; i++) {
variant = var->data.as_array->entries[i];
ret = mp_cfl_to_msgpack(variant, mp_sbuf, mp_pck);
Expand Down

0 comments on commit 1ce8d04

Please sign in to comment.