diff options
author | Craig Tiller <ctiller@google.com> | 2016-11-21 13:46:31 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2016-11-21 13:46:31 -0800 |
commit | 3b05e1da916aa298fe58a58ec79a7f7c043534c7 (patch) | |
tree | 72353f42667b389f913e6a5164019199000eded7 /src/core/lib/transport | |
parent | 73ee7dc5590447bc726f7a1c3e51c2a217c8d5b6 (diff) |
Move from cmp --> eq, and provide a good implementation for interning
Diffstat (limited to 'src/core/lib/transport')
-rw-r--r-- | src/core/lib/transport/metadata.c | 8 | ||||
-rw-r--r-- | src/core/lib/transport/metadata.h | 11 | ||||
-rw-r--r-- | src/core/lib/transport/static_metadata.c | 2 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 2082d1bac2..f9f5ac9dd2 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -279,8 +279,7 @@ grpc_mdelem grpc_mdelem_create( idx = TABLE_IDX(hash, shard->capacity); /* search for an existing pair */ for (md = shard->elems[idx]; md; md = md->bucket_next) { - if (grpc_slice_cmp(key, md->key) == 0 && - grpc_slice_cmp(value, md->value) == 0) { + if (grpc_slice_eq(key, md->key) && grpc_slice_eq(value, md->value)) { REF_MD_LOCKED(shard, md); gpr_mu_unlock(&shard->mu); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); @@ -496,7 +495,8 @@ void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { if (a.payload == b.payload) return true; + if (GRPC_MDELEM_IS_INTERNED(a) && GRPC_MDELEM_IS_INTERNED(b)) return false; if (GRPC_MDISNULL(a) || GRPC_MDISNULL(b)) return false; - return 0 == grpc_slice_cmp(GRPC_MDKEY(a), GRPC_MDKEY(b)) && - 0 == grpc_slice_cmp(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); + return grpc_slice_eq(GRPC_MDKEY(a), GRPC_MDKEY(b)) && + grpc_slice_eq(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); } diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 6d0afbe789..f4ba86c854 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -86,17 +86,21 @@ typedef struct grpc_mdelem_data { /* there is a private part to this in metadata.c */ } grpc_mdelem_data; +/* GRPC_MDELEM_STORAGE_* enum values that can be treated as interned always have + this bit set in their integer value */ +#define GRPC_MDELEM_STORAGE_INTERNED_BIT 1 + typedef enum { /* memory pointed to by grpc_mdelem::payload is owned by an external system */ GRPC_MDELEM_STORAGE_EXTERNAL = 0, /* memory pointed to by grpc_mdelem::payload is interned by the metadata system */ - GRPC_MDELEM_STORAGE_INTERNED = 1, + GRPC_MDELEM_STORAGE_INTERNED = GRPC_MDELEM_STORAGE_INTERNED_BIT, /* memory pointed to by grpc_mdelem::payload is allocated by the metadata system */ GRPC_MDELEM_STORAGE_ALLOCATED = 2, /* memory is in the static metadata table */ - GRPC_MDELEM_STORAGE_STATIC = 3, + GRPC_MDELEM_STORAGE_STATIC = 2 | GRPC_MDELEM_STORAGE_INTERNED_BIT, } grpc_mdelem_data_storage; struct grpc_mdelem { @@ -111,6 +115,9 @@ struct grpc_mdelem { ((grpc_mdelem_data_storage)((md).payload & (uintptr_t)3)) #define GRPC_MAKE_MDELEM(data, storage) \ ((grpc_mdelem){((uintptr_t)(data)) | ((uintptr_t)storage)}) +#define GRPC_MDELEM_IS_INTERNED(md) \ + ((grpc_mdelem_data_storage)((md).payload & \ + (uintptr_t)GRPC_MDELEM_STORAGE_INTERNED_BIT)) /* Unrefs the slices. */ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 575f442a9b..374a5fd615 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -117,7 +117,7 @@ static uint8_t g_raw_bytes[] = { static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable static_vtable = { - static_ref, static_unref, grpc_static_slice_hash}; + static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash}; static grpc_slice_refcount g_refcnt = {&static_vtable}; bool grpc_is_static_metadata_string(grpc_slice slice) { |