refactor(map): get rid of spurious subsystem_init() functions due to maps

This commit is contained in:
Björn Linse
2021-08-22 10:40:16 +02:00
parent 6d23a58b7d
commit b2277a4279
6 changed files with 25 additions and 45 deletions

View File

@@ -1725,7 +1725,7 @@ const char *describe_ns(NS ns_id)
{ {
String name; String name;
handle_T id; handle_T id;
map_foreach(namespace_ids, name, id, { map_foreach((&namespace_ids), name, id, {
if ((NS)id == ns_id && name.size) { if ((NS)id == ns_id && name.size) {
return name.data; return name.data;
} }

View File

@@ -37,24 +37,18 @@ typedef struct {
bool wildmenu_active; bool wildmenu_active;
} UIData; } UIData;
static PMap(uint64_t) *connected_uis = NULL; static PMap(uint64_t) connected_uis = MAP_INIT;
void remote_ui_init(void)
FUNC_API_NOEXPORT
{
connected_uis = pmap_new(uint64_t)();
}
void remote_ui_disconnect(uint64_t channel_id) void remote_ui_disconnect(uint64_t channel_id)
FUNC_API_NOEXPORT FUNC_API_NOEXPORT
{ {
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
if (!ui) { if (!ui) {
return; return;
} }
UIData *data = ui->data; UIData *data = ui->data;
api_free_array(data->buffer); // Destroy pending screen updates. api_free_array(data->buffer); // Destroy pending screen updates.
pmap_del(uint64_t)(connected_uis, channel_id); pmap_del(uint64_t)(&connected_uis, channel_id);
xfree(ui->data); xfree(ui->data);
ui->data = NULL; // Flag UI as "stopped". ui->data = NULL; // Flag UI as "stopped".
ui_detach_impl(ui, channel_id); ui_detach_impl(ui, channel_id);
@@ -73,7 +67,7 @@ void remote_ui_wait_for_attach(void)
} }
LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1, LOOP_PROCESS_EVENTS_UNTIL(&main_loop, channel->events, -1,
pmap_has(uint64_t)(connected_uis, CHAN_STDIO)); pmap_has(uint64_t)(&connected_uis, CHAN_STDIO));
} }
/// Activates UI events on the channel. /// Activates UI events on the channel.
@@ -95,7 +89,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
Dictionary options, Error *err) Dictionary options, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{ {
if (pmap_has(uint64_t)(connected_uis, channel_id)) { if (pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI already attached to channel: %" PRId64, channel_id); "UI already attached to channel: %" PRId64, channel_id);
return; return;
@@ -172,7 +166,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
data->wildmenu_active = false; data->wildmenu_active = false;
ui->data = data; ui->data = data;
pmap_put(uint64_t)(connected_uis, channel_id, ui); pmap_put(uint64_t)(&connected_uis, channel_id, ui);
ui_attach_impl(ui, channel_id); ui_attach_impl(ui, channel_id);
} }
@@ -195,7 +189,7 @@ void ui_attach(uint64_t channel_id, Integer width, Integer height,
void nvim_ui_detach(uint64_t channel_id, Error *err) void nvim_ui_detach(uint64_t channel_id, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
@@ -208,7 +202,7 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
Integer height, Error *err) Integer height, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
@@ -220,7 +214,7 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
return; return;
} }
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
ui->width = (int)width; ui->width = (int)width;
ui->height = (int)height; ui->height = (int)height;
ui_refresh(); ui_refresh();
@@ -230,12 +224,12 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
Object value, Error *error) Object value, Error *error)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(error, kErrorTypeException, api_set_error(error, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
} }
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
ui_set_option(ui, false, name, value, error); ui_set_option(ui, false, name, value, error);
} }
@@ -310,7 +304,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width,
Integer height, Error *err) Integer height, Error *err)
FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
@@ -328,7 +322,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width,
void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err) void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(6) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
@@ -339,7 +333,7 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
return; return;
} }
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
if (!ui->ui_ext[kUIPopupmenu]) { if (!ui->ui_ext[kUIPopupmenu]) {
api_set_error(err, kErrorTypeValidation, api_set_error(err, kErrorTypeValidation,
"It must support the ext_popupmenu option"); "It must support the ext_popupmenu option");
@@ -369,13 +363,13 @@ void nvim_ui_pum_set_bounds(uint64_t channel_id, Float width, Float height,
Float row, Float col, Error *err) Float row, Float col, Error *err)
FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY FUNC_API_SINCE(7) FUNC_API_REMOTE_ONLY
{ {
if (!pmap_has(uint64_t)(connected_uis, channel_id)) { if (!pmap_has(uint64_t)(&connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id); "UI not attached to channel: %" PRId64, channel_id);
return; return;
} }
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); UI *ui = pmap_get(uint64_t)(&connected_uis, channel_id);
if (!ui->ui_ext[kUIPopupmenu]) { if (!ui->ui_ext[kUIPopupmenu]) {
api_set_error(err, kErrorTypeValidation, api_set_error(err, kErrorTypeValidation,
"UI must support the ext_popupmenu option"); "UI must support the ext_popupmenu option");

View File

@@ -58,22 +58,16 @@
# include "api/vim.c.generated.h" # include "api/vim.c.generated.h"
#endif #endif
void api_vim_init(void)
FUNC_API_NOEXPORT
{
namespace_ids = map_new(String, handle_T)();
}
void api_vim_free_all_mem(void) void api_vim_free_all_mem(void)
FUNC_API_NOEXPORT FUNC_API_NOEXPORT
{ {
String name; String name;
handle_T id; handle_T id;
map_foreach(namespace_ids, name, id, { map_foreach((&namespace_ids), name, id, {
(void)id; (void)id;
xfree(name.data); xfree(name.data);
}) })
map_free(String, handle_T)(namespace_ids); map_destroy(String, handle_T)(&namespace_ids);
} }
/// Executes Vimscript (multiline block of Ex-commands), like anonymous /// Executes Vimscript (multiline block of Ex-commands), like anonymous
@@ -1568,14 +1562,14 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
Integer nvim_create_namespace(String name) Integer nvim_create_namespace(String name)
FUNC_API_SINCE(5) FUNC_API_SINCE(5)
{ {
handle_T id = map_get(String, handle_T)(namespace_ids, name); handle_T id = map_get(String, handle_T)(&namespace_ids, name);
if (id > 0) { if (id > 0) {
return id; return id;
} }
id = next_namespace_id++; id = next_namespace_id++;
if (name.size > 0) { if (name.size > 0) {
String name_alloc = copy_string(name); String name_alloc = copy_string(name);
map_put(String, handle_T)(namespace_ids, name_alloc, id); map_put(String, handle_T)(&namespace_ids, name_alloc, id);
} }
return (Integer)id; return (Integer)id;
} }
@@ -1590,7 +1584,7 @@ Dictionary nvim_get_namespaces(void)
String name; String name;
handle_T id; handle_T id;
map_foreach(namespace_ids, name, id, { map_foreach((&namespace_ids), name, id, {
PUT(retval, name.data, INTEGER_OBJ(id)); PUT(retval, name.data, INTEGER_OBJ(id));
}) })

View File

@@ -6,7 +6,7 @@
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/map.h" #include "nvim/map.h"
EXTERN Map(String, handle_T) *namespace_ids INIT(= NULL); EXTERN Map(String, handle_T) namespace_ids INIT(= MAP_INIT);
EXTERN handle_T next_namespace_id INIT(= 1); EXTERN handle_T next_namespace_id INIT(= 1);
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS

View File

@@ -13,12 +13,7 @@
# include "decoration.c.generated.h" # include "decoration.c.generated.h"
#endif #endif
static PMap(uint64_t) *hl_decors; static PMap(uint64_t) hl_decors;
void decor_init(void)
{
hl_decors = pmap_new(uint64_t)();
}
/// Add highlighting to a buffer, bounded by two cursor positions, /// Add highlighting to a buffer, bounded by two cursor positions,
/// with an offset. /// with an offset.
@@ -77,7 +72,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf,
Decoration *decor_hl(int hl_id) Decoration *decor_hl(int hl_id)
{ {
assert(hl_id > 0); assert(hl_id > 0);
Decoration **dp = (Decoration **)pmap_ref(uint64_t)(hl_decors, Decoration **dp = (Decoration **)pmap_ref(uint64_t)(&hl_decors,
(uint64_t)hl_id, true); (uint64_t)hl_id, true);
if (*dp) { if (*dp) {
return *dp; return *dp;

View File

@@ -126,8 +126,6 @@ void event_init(void)
signal_init(); signal_init();
// finish mspgack-rpc initialization // finish mspgack-rpc initialization
channel_init(); channel_init();
remote_ui_init();
api_vim_init();
terminal_init(); terminal_init();
ui_init(); ui_init();
} }
@@ -161,7 +159,6 @@ void early_init(mparm_T *paramp)
env_init(); env_init();
fs_init(); fs_init();
handle_init(); handle_init();
decor_init();
eval_init(); // init global variables eval_init(); // init global variables
init_path(argv0 ? argv0 : "nvim"); init_path(argv0 ? argv0 : "nvim");
init_normal_cmds(); // Init the table of Normal mode commands. init_normal_cmds(); // Init the table of Normal mode commands.