Skip to content

Commit

Permalink
filter_nest: Optimize helper_pack_string function
Browse files Browse the repository at this point in the history
This changes adds the length of the string to the signature of the
helper function to avoid repeated strlen() calls. Invocations have been
updated to pass it.

Signed-off-by: Michiel Kalkman <mkalkman@shelde.com>
  • Loading branch information
Michiel Kalkman committed Apr 9, 2018
1 parent 694720a commit 94780d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/filter_nest/nest.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static int configure(struct filter_nest_ctx *ctx,
tmp = flb_filter_get_property("Nest_under", f_ins);
if (tmp) {
ctx->nesting_key = flb_strdup(tmp);
ctx->nesting_key_len = strlen(tmp);
}
else {
flb_error("[filter_parser] Key \"Nest_under\" is missing\n");
Expand Down Expand Up @@ -73,13 +74,12 @@ static int configure(struct filter_nest_ctx *ctx,
return 0;
}

static void helper_pack_string(msgpack_packer *packer, const char *str)
static void helper_pack_string(msgpack_packer *packer, const char *str, int len)
{
if (str == NULL) {
msgpack_pack_nil(packer);
}
else {
int len = (int) strlen(str);
msgpack_pack_str(packer, len);
msgpack_pack_str_body(packer, str, len);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ static inline void apply_nesting_rules(msgpack_packer * packer,
map_pack_each_if(packer, &map, ctx, &is_not_kv_to_nest);

// * * * Pack the nested map key
helper_pack_string(packer, ctx->nesting_key);
helper_pack_string(packer, ctx->nesting_key, ctx->nesting_key_len);

// * * * Create the nest map value
msgpack_pack_map(packer, items_to_nest_count);
Expand Down
1 change: 1 addition & 0 deletions plugins/filter_nest/nest.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
struct filter_nest_ctx
{
char *nesting_key;
int nesting_key_len;
char *wildcard;
int wildcard_len;
bool wildcard_is_dynamic;
Expand Down

0 comments on commit 94780d5

Please sign in to comment.