diff options
author | ctiller <ctiller@google.com> | 2014-12-11 09:15:41 -0800 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2014-12-11 15:11:44 -0800 |
commit | 430c4996e80b60c7a0dac760e224fb9ea0128690 (patch) | |
tree | a0ce34bec8ece128a6d03eb64758c8aa9b69a742 /src/core/transport | |
parent | ccd27fd9b2cc3c2f83dc9a7632f6a2d5f0438c45 (diff) |
Cache encoded binary data on the metadata string object.
Change on 2014/12/11 by ctiller <ctiller@google.com>
-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=81882793
Diffstat (limited to 'src/core/transport')
-rw-r--r-- | src/core/transport/metadata.c | 22 | ||||
-rw-r--r-- | src/core/transport/metadata.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/core/transport/metadata.c b/src/core/transport/metadata.c index ceb77df34d..9edfd5bfd1 100644 --- a/src/core/transport/metadata.c +++ b/src/core/transport/metadata.c @@ -39,6 +39,7 @@ #include <grpc/support/alloc.h> #include <grpc/support/log.h> #include "src/core/support/murmur_hash.h" +#include "src/core/transport/chttp2/bin_encoder.h" #include <grpc/support/time.h> #define INITIAL_STRTAB_CAPACITY 4 @@ -53,8 +54,11 @@ typedef struct internal_string { /* private only data */ gpr_uint32 refs; + gpr_uint8 has_base64_and_huffman_encoded; gpr_slice_refcount refcount; + gpr_slice base64_and_huffman; + grpc_mdctx *context; struct internal_string *bucket_next; @@ -225,6 +229,9 @@ static void internal_destroy_string(internal_string *is) { internal_string **prev_next; internal_string *cur; grpc_mdctx *ctx = is->context; + if (is->has_base64_and_huffman_encoded) { + gpr_slice_unref(is->base64_and_huffman); + } for (prev_next = &ctx->strtab[is->hash % ctx->strtab_capacity], cur = *prev_next; cur != is; prev_next = &cur->bucket_next, cur = cur->bucket_next) @@ -312,6 +319,7 @@ grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *buf, /* add a null terminator for cheap c string conversion when desired */ s->slice.data.refcounted.bytes[length] = 0; } + s->has_base64_and_huffman_encoded = 0; s->hash = hash; s->context = ctx; s->bucket_next = ctx->strtab[hash % ctx->strtab_capacity]; @@ -523,3 +531,17 @@ void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), im->destroy_user_data = destroy_func; im->user_data = user_data; } + +gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *gs) { + internal_string *s = (internal_string *)gs; + gpr_slice slice; + grpc_mdctx *ctx = s->context; + lock(ctx); + if (!s->has_base64_and_huffman_encoded) { + s->base64_and_huffman = + grpc_chttp2_base64_encode_and_huffman_compress(s->slice); + } + slice = s->base64_and_huffman; + unlock(ctx); + return slice; +} diff --git a/src/core/transport/metadata.h b/src/core/transport/metadata.h index 4b87f70e31..9fca3d4bd5 100644 --- a/src/core/transport/metadata.h +++ b/src/core/transport/metadata.h @@ -98,6 +98,10 @@ grpc_mdstr *grpc_mdstr_from_slice(grpc_mdctx *ctx, gpr_slice slice); grpc_mdstr *grpc_mdstr_from_buffer(grpc_mdctx *ctx, const gpr_uint8 *str, size_t length); +/* Returns a borrowed slice from the mdstr with its contents base64 encoded + and huffman compressed */ +gpr_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *str); + /* Constructors for grpc_mdelem instances; take a variety of data types that clients may have handy */ grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_mdctx *ctx, grpc_mdstr *key, |