mirror of
https://github.com/neovim/neovim.git
synced 2025-10-02 16:08:36 +00:00
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.
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user