aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/map.c
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-05-19 10:52:04 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-05-19 10:52:04 -0300
commit974eade1a6445222812fc03f60896def74b7dd06 (patch)
tree1e08bfbe66124ec2e3b2bc54f2034a17f89cb472 /src/nvim/map.c
parenteb7513bbd2bd9189502159c4146bb6999b8da32b (diff)
downloadrneovim-974eade1a6445222812fc03f60896def74b7dd06.tar.gz
rneovim-974eade1a6445222812fc03f60896def74b7dd06.tar.bz2
rneovim-974eade1a6445222812fc03f60896def74b7dd06.zip
Improve map module: Change scopes
- Move `Map` structure definition to `map_defs.h` - Use `KHASH_DECLARE` on map_defs.h to declare khash function prototypes. - Redefine `map_foreach` into a macro - Refactor server.c module to use the new `map_foreach` macro.
Diffstat (limited to 'src/nvim/map.c')
-rw-r--r--src/nvim/map.c29
1 files changed, 5 insertions, 24 deletions
diff --git a/src/nvim/map.c b/src/nvim/map.c
index 332de6d3d3..91a90b4493 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -8,15 +8,7 @@
#include "nvim/lib/khash.h"
-typedef struct {
- void *ptr;
-} Value;
-
-KHASH_MAP_INIT_STR(Map, Value)
-
-struct map {
- khash_t(Map) *table;
-};
+__KHASH_IMPL(Map,, kh_cstr_t, void *, 1, kh_str_hash_func, kh_str_hash_equal)
Map *map_new()
{
@@ -40,7 +32,7 @@ void *map_get(Map *map, const char *key)
return NULL;
}
- return kh_val(map->table, k).ptr;
+ return kh_val(map->table, k);
}
bool map_has(Map *map, const char *key)
@@ -53,15 +45,14 @@ void *map_put(Map *map, const char *key, void *value)
int ret;
void *rv = NULL;
khiter_t k = kh_put(Map, map->table, key, &ret);
- Value val = {.ptr = value};
if (!ret) {
// key present, return the current value
- rv = kh_val(map->table, k).ptr;
+ rv = kh_val(map->table, k);
kh_del(Map, map->table, k);
}
- kh_val(map->table, k) = val;
+ kh_val(map->table, k) = value;
return rv;
}
@@ -72,20 +63,10 @@ void *map_del(Map *map, const char *key)
khiter_t k;
if ((k = kh_get(Map, map->table, key)) != kh_end(map->table)) {
- rv = kh_val(map->table, k).ptr;
+ rv = kh_val(map->table, k);
kh_del(Map, map->table, k);
}
return rv;
}
-void map_foreach(Map *map, key_value_cb cb)
-{
- const char *key;
- Value value;
-
- kh_foreach(map->table, key, value, {
- cb(map, (const char *)key, value.ptr);
- });
-}
-