aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/map.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-08-22 09:54:21 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2021-08-22 09:54:21 +0200
commit9e651a9d097c5715c0f025555814fa0ad18ca8cd (patch)
treea5ef7d056f6864f114e1285048e2a3f1e5bb9a51 /src/nvim/map.c
parent8331cd13c45fb75bff0cec328ccba79b3ae61fa5 (diff)
downloadrneovim-9e651a9d097c5715c0f025555814fa0ad18ca8cd.tar.gz
rneovim-9e651a9d097c5715c0f025555814fa0ad18ca8cd.tar.bz2
rneovim-9e651a9d097c5715c0f025555814fa0ad18ca8cd.zip
perf(map): reduce double pointer indirection to single pointer indirection
the only field of Map(...) was a pointer to a khash_t. make it contain the struct by value instead.
Diffstat (limited to 'src/nvim/map.c')
-rw-r--r--src/nvim/map.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/nvim/map.c b/src/nvim/map.c
index 86dc257e40..10baa82f5a 100644
--- a/src/nvim/map.c
+++ b/src/nvim/map.c
@@ -56,14 +56,14 @@
\
Map(T, U) *map_##T##_##U##_new() \
{ \
- Map(T, U) *rv = xmalloc(sizeof(Map(T, U))); \
- rv->table = kh_init(T##_##U##_map); \
+ Map(T, U) *rv = xcalloc(1, sizeof(Map(T, U))); \
+ /* khash_t table member is zero-initialized */ \
return rv; \
} \
\
void map_##T##_##U##_free(Map(T, U) *map) \
{ \
- kh_destroy(T##_##U##_map, map->table); \
+ kh_dealloc(T##_##U##_map, &map->table); \
xfree(map); \
} \
\
@@ -71,39 +71,39 @@
{ \
khiter_t k; \
\
- if ((k = kh_get(T##_##U##_map, map->table, key)) == kh_end(map->table)) { \
+ if ((k = kh_get(T##_##U##_map, &map->table, key)) == kh_end(&map->table)) { \
return INITIALIZER(T, U); \
} \
\
- return kh_val(map->table, k); \
+ return kh_val(&map->table, k); \
} \
\
bool map_##T##_##U##_has(Map(T, U) *map, T key) \
{ \
- return kh_get(T##_##U##_map, map->table, key) != kh_end(map->table); \
+ return kh_get(T##_##U##_map, &map->table, key) != kh_end(&map->table); \
} \
\
T map_##T##_##U##_key(Map(T, U) *map, T key) \
{ \
khiter_t k; \
\
- if ((k = kh_get(T##_##U##_map, map->table, key)) == kh_end(map->table)) { \
+ if ((k = kh_get(T##_##U##_map, &map->table, key)) == kh_end(&map->table)) { \
abort(); /* Caller must check map_has(). */ \
} \
\
- return kh_key(map->table, k); \
+ return kh_key(&map->table, k); \
} \
U map_##T##_##U##_put(Map(T, U) *map, T key, U value) \
{ \
int ret; \
U rv = INITIALIZER(T, U); \
- khiter_t k = kh_put(T##_##U##_map, map->table, key, &ret); \
+ khiter_t k = kh_put(T##_##U##_map, &map->table, key, &ret); \
\
if (!ret) { \
- rv = kh_val(map->table, k); \
+ rv = kh_val(&map->table, k); \
} \
\
- kh_val(map->table, k) = value; \
+ kh_val(&map->table, k) = value; \
return rv; \
} \
\
@@ -112,18 +112,18 @@
int ret; \
khiter_t k; \
if (put) { \
- k = kh_put(T##_##U##_map, map->table, key, &ret); \
+ k = kh_put(T##_##U##_map, &map->table, key, &ret); \
if (ret) { \
- kh_val(map->table, k) = INITIALIZER(T, U); \
+ kh_val(&map->table, k) = INITIALIZER(T, U); \
} \
} else { \
- k = kh_get(T##_##U##_map, map->table, key); \
- if (k == kh_end(map->table)) { \
+ k = kh_get(T##_##U##_map, &map->table, key); \
+ if (k == kh_end(&map->table)) { \
return NULL; \
} \
} \
\
- return &kh_val(map->table, k); \
+ return &kh_val(&map->table, k); \
} \
\
U map_##T##_##U##_del(Map(T, U) *map, T key) \
@@ -131,9 +131,9 @@
U rv = INITIALIZER(T, U); \
khiter_t k; \
\
- if ((k = kh_get(T##_##U##_map, map->table, key)) != kh_end(map->table)) { \
- rv = kh_val(map->table, k); \
- kh_del(T##_##U##_map, map->table, k); \
+ if ((k = kh_get(T##_##U##_map, &map->table, key)) != kh_end(&map->table)) { \
+ rv = kh_val(&map->table, k); \
+ kh_del(T##_##U##_map, &map->table, k); \
} \
\
return rv; \
@@ -141,7 +141,7 @@
\
void map_##T##_##U##_clear(Map(T, U) *map) \
{ \
- kh_clear(T##_##U##_map, map->table); \
+ kh_clear(T##_##U##_map, &map->table); \
}
static inline khint_t String_hash(String s)