From 68d8ccc741df3180e0bc779f1ae42e14146ca04f Mon Sep 17 00:00:00 2001 From: Konstantin Osipov <kostja@tarantool.org> Date: Wed, 24 Jul 2013 19:52:17 +0400 Subject: [PATCH] Define mh_key_t in mh_i32ptr_hash to enable mh_find(). --- include/assoc.h | 5 ++++- src/box/space.cc | 6 ++---- src/fiber.cc | 3 +-- src/session.cc | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/assoc.h b/include/assoc.h index 64f6c30b04..9b653d16c7 100644 --- a/include/assoc.h +++ b/include/assoc.h @@ -36,14 +36,17 @@ * Map: (i32) => (void *) */ #define mh_name _i32ptr +#define mh_key_t uint32_t struct mh_i32ptr_node_t { - uint32_t key; + mh_key_t key; void *val; }; #define mh_node_t struct mh_i32ptr_node_t #define mh_arg_t void * #define mh_hash(a, arg) (a->key) +#define mh_hash_key(a, arg) (a) #define mh_eq(a, b, arg) ((a->key) == (b->key)) +#define mh_eq_key(a, b, arg) ((a) == (b->key)) #include <mhash.h> diff --git a/src/box/space.cc b/src/box/space.cc index f0d8cc7192..676cfc1a61 100644 --- a/src/box/space.cc +++ b/src/box/space.cc @@ -121,8 +121,7 @@ space_delete(struct space *space) { if (tarantool_L) box_lua_space_delete(tarantool_L, space); - const struct mh_i32ptr_node_t node = { space_id(space), NULL }; - mh_int_t k = mh_i32ptr_get(spaces, &node, NULL); + mh_int_t k = mh_i32ptr_find(spaces, space_id(space), NULL); assert(k != mh_end(spaces)); mh_i32ptr_del(spaces, k, NULL); for (uint32_t j = 0 ; j <= space->index_id_max; j++) @@ -134,8 +133,7 @@ space_delete(struct space *space) struct space * space_by_id(uint32_t id) { - const struct mh_i32ptr_node_t node = { id, NULL }; - mh_int_t space = mh_i32ptr_get(spaces, &node, NULL); + mh_int_t space = mh_i32ptr_find(spaces, id, NULL); if (space == mh_end(spaces)) return NULL; return (struct space *) mh_i32ptr_node(spaces, space)->val; diff --git a/src/fiber.cc b/src/fiber.cc index faa8811526..d539d702ef 100644 --- a/src/fiber.cc +++ b/src/fiber.cc @@ -321,8 +321,7 @@ fiber_ready_async(ev_async *watcher, int revents) struct fiber * fiber_find(uint32_t fid) { - struct mh_i32ptr_node_t node = { fid, NULL }; - mh_int_t k = mh_i32ptr_get(fiber_registry, &node, NULL); + mh_int_t k = mh_i32ptr_find(fiber_registry, fid, NULL); if (k == mh_end(fiber_registry)) return NULL; diff --git a/src/session.cc b/src/session.cc index 85ecb8d049..be2f6d5606 100644 --- a/src/session.cc +++ b/src/session.cc @@ -93,8 +93,7 @@ session_destroy(uint32_t sid) int session_fd(uint32_t sid) { - struct mh_i32ptr_node_t node = { sid, NULL }; - mh_int_t k = mh_i32ptr_get(session_registry, &node, NULL); + mh_int_t k = mh_i32ptr_find(session_registry, sid, NULL); return k == mh_end(session_registry) ? -1 : (intptr_t) mh_i32ptr_node(session_registry, k)->val; } -- GitLab