mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07: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:
parent
8331cd13c4
commit
9e651a9d09
@ -7331,7 +7331,7 @@ void add_timer_info(typval_T *rettv, timer_T *timer)
|
|||||||
|
|
||||||
void add_timer_info_all(typval_T *rettv)
|
void add_timer_info_all(typval_T *rettv)
|
||||||
{
|
{
|
||||||
tv_list_alloc_ret(rettv, timers->table->n_occupied);
|
tv_list_alloc_ret(rettv, map_size(timers));
|
||||||
timer_T *timer;
|
timer_T *timer;
|
||||||
map_foreach_value(timers, timer, {
|
map_foreach_value(timers, timer, {
|
||||||
if (!timer->stopped) {
|
if (!timer->stopped) {
|
||||||
|
@ -56,14 +56,14 @@
|
|||||||
\
|
\
|
||||||
Map(T, U) *map_##T##_##U##_new() \
|
Map(T, U) *map_##T##_##U##_new() \
|
||||||
{ \
|
{ \
|
||||||
Map(T, U) *rv = xmalloc(sizeof(Map(T, U))); \
|
Map(T, U) *rv = xcalloc(1, sizeof(Map(T, U))); \
|
||||||
rv->table = kh_init(T##_##U##_map); \
|
/* khash_t table member is zero-initialized */ \
|
||||||
return rv; \
|
return rv; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void map_##T##_##U##_free(Map(T, U) *map) \
|
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); \
|
xfree(map); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@ -71,39 +71,39 @@
|
|||||||
{ \
|
{ \
|
||||||
khiter_t k; \
|
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 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) \
|
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) \
|
T map_##T##_##U##_key(Map(T, U) *map, T key) \
|
||||||
{ \
|
{ \
|
||||||
khiter_t k; \
|
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(). */ \
|
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) \
|
U map_##T##_##U##_put(Map(T, U) *map, T key, U value) \
|
||||||
{ \
|
{ \
|
||||||
int ret; \
|
int ret; \
|
||||||
U rv = INITIALIZER(T, U); \
|
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) { \
|
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; \
|
return rv; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@ -112,18 +112,18 @@
|
|||||||
int ret; \
|
int ret; \
|
||||||
khiter_t k; \
|
khiter_t k; \
|
||||||
if (put) { \
|
if (put) { \
|
||||||
k = kh_put(T##_##U##_map, map->table, key, &ret); \
|
k = kh_put(T##_##U##_map, &map->table, key, &ret); \
|
||||||
if (ret) { \
|
if (ret) { \
|
||||||
kh_val(map->table, k) = INITIALIZER(T, U); \
|
kh_val(&map->table, k) = INITIALIZER(T, U); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
k = kh_get(T##_##U##_map, map->table, key); \
|
k = kh_get(T##_##U##_map, &map->table, key); \
|
||||||
if (k == kh_end(map->table)) { \
|
if (k == kh_end(&map->table)) { \
|
||||||
return NULL; \
|
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) \
|
U map_##T##_##U##_del(Map(T, U) *map, T key) \
|
||||||
@ -131,9 +131,9 @@
|
|||||||
U rv = INITIALIZER(T, U); \
|
U rv = INITIALIZER(T, U); \
|
||||||
khiter_t k; \
|
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)) { \
|
||||||
rv = kh_val(map->table, k); \
|
rv = kh_val(&map->table, k); \
|
||||||
kh_del(T##_##U##_map, map->table, k); \
|
kh_del(T##_##U##_map, &map->table, k); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return rv; \
|
return rv; \
|
||||||
@ -141,7 +141,7 @@
|
|||||||
\
|
\
|
||||||
void map_##T##_##U##_clear(Map(T, U) *map) \
|
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)
|
static inline khint_t String_hash(String s)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
KHASH_DECLARE(T##_##U##_map, T, U) \
|
KHASH_DECLARE(T##_##U##_map, T, U) \
|
||||||
\
|
\
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
khash_t(T##_##U##_map) *table; \
|
khash_t(T##_##U##_map) table; \
|
||||||
} Map(T, U); \
|
} Map(T, U); \
|
||||||
\
|
\
|
||||||
Map(T, U) *map_##T##_##U##_new(void); \
|
Map(T, U) *map_##T##_##U##_new(void); \
|
||||||
@ -68,7 +68,7 @@ MAP_DECLS(ColorKey, ColorItem)
|
|||||||
#define map_del(T, U) map_##T##_##U##_del
|
#define map_del(T, U) map_##T##_##U##_del
|
||||||
#define map_clear(T, U) map_##T##_##U##_clear
|
#define map_clear(T, U) map_##T##_##U##_clear
|
||||||
|
|
||||||
#define map_size(map) ((map)->table->size)
|
#define map_size(map) ((map)->table.size)
|
||||||
|
|
||||||
#define pmap_new(T) map_new(T, ptr_t)
|
#define pmap_new(T) map_new(T, ptr_t)
|
||||||
#define pmap_free(T) map_free(T, ptr_t)
|
#define pmap_free(T) map_free(T, ptr_t)
|
||||||
@ -82,10 +82,10 @@ MAP_DECLS(ColorKey, ColorItem)
|
|||||||
#define pmap_clear(T) map_clear(T, ptr_t)
|
#define pmap_clear(T) map_clear(T, ptr_t)
|
||||||
|
|
||||||
#define map_foreach(map, key, value, block) \
|
#define map_foreach(map, key, value, block) \
|
||||||
kh_foreach(map->table, key, value, block)
|
kh_foreach(&map->table, key, value, block)
|
||||||
|
|
||||||
#define map_foreach_value(map, value, block) \
|
#define map_foreach_value(map, value, block) \
|
||||||
kh_foreach_value(map->table, value, block)
|
kh_foreach_value(&map->table, value, block)
|
||||||
|
|
||||||
void pmap_del2(PMap(cstr_t) *map, const char *key);
|
void pmap_del2(PMap(cstr_t) *map, const char *key);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user