Use mdelem's user data caching

pull/10849/head
Muxi Yan 8 years ago
parent d64e70a815
commit 384d8ffaaa
  1. 2
      src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c
  2. 12
      src/core/ext/filters/workarounds/workaround_utils.c

@ -87,8 +87,6 @@ static void recv_initial_metadata_ready(grpc_exec_ctx* exec_ctx,
->workaround_active[GRPC_WORKAROUND_ID_CRONET_COMPRESSION]) {
calld->workaround_active = true;
}
// Remove with caching
gpr_free(user_agent_md);
}
}

@ -34,19 +34,25 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
static void destroy_user_agent_md(void *user_agent_md) {
gpr_free(user_agent_md);
}
static user_agent_parser user_agent_parsers[GRPC_MAX_WORKAROUND_ID];
grpc_user_agent_md *grpc_parse_user_agent(grpc_mdelem md) {
grpc_user_agent_md *user_agent_md;
// USE THE CACHE WHEN ABLE
grpc_user_agent_md *user_agent_md = (grpc_user_agent_md*)grpc_mdelem_get_user_data(md, destroy_user_agent_md);
if (NULL != user_agent_md) {
return user_agent_md;
}
user_agent_md = gpr_malloc(sizeof(grpc_user_agent_md));
for (int i = 0; i < GRPC_MAX_WORKAROUND_ID; i++) {
if (user_agent_parsers[i]) {
user_agent_md->workaround_active[i] = user_agent_parsers[i](md);
}
}
grpc_mdelem_set_user_data(md, destroy_user_agent_md, (void *)user_agent_md);
return user_agent_md;
}

Loading…
Cancel
Save