From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/ui.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 6d09b9f3a3..24f20af2f3 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -127,10 +127,10 @@ void ui_free_all_mem(void) kv_destroy(call_buf); UIEventCallback *event_cb; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_foreach_value(&ui_event_cbs, event_cb, { free_ui_event_callback(event_cb); }) - pmap_destroy(uint32_t)(&ui_event_cbs); + map_destroy(uint32_t, &ui_event_cbs); } #endif @@ -660,7 +660,7 @@ void ui_call_event(char *name, Array args) { UIEventCallback *event_cb; bool handled = false; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_foreach_value(&ui_event_cbs, event_cb, { Error err = ERROR_INIT; Object res = nlua_call_ref(event_cb->cb, name, args, false, &err); if (res.type == kObjectTypeBoolean && res.data.boolean == true) { @@ -686,7 +686,7 @@ void ui_cb_update_ext(void) for (size_t i = 0; i < kUIGlobalCount; i++) { UIEventCallback *event_cb; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_foreach_value(&ui_event_cbs, event_cb, { if (event_cb->ext_widgets[i]) { ui_cb_ext[i] = true; break; @@ -710,9 +710,9 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) event_cb->ext_widgets[kUICmdline] = true; } - UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); + ptr_t *item = pmap_put_ref(uint32_t)(&ui_event_cbs, ns_id, NULL, NULL); if (*item) { - free_ui_event_callback(*item); + free_ui_event_callback((UIEventCallback *)(*item)); } *item = event_cb; @@ -723,8 +723,8 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) void ui_remove_cb(uint32_t ns_id) { if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { - free_ui_event_callback(pmap_get(uint32_t)(&ui_event_cbs, ns_id)); - pmap_del(uint32_t)(&ui_event_cbs, ns_id); + UIEventCallback *item = pmap_del(uint32_t)(&ui_event_cbs, ns_id, NULL); + free_ui_event_callback(item); } ui_cb_update_ext(); ui_refresh(); -- cgit