aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-08-22 10:40:16 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2021-08-22 10:46:04 +0200
commitb2277a42790907424ed2cd37d3d991650bb88441 (patch)
tree4bee894c7c1577e95fb7cd6133a77c600b2bb554
parent6d23a58b7d27a42de9c20a1492c07aeaffc956b6 (diff)
downloadrneovim-b2277a42790907424ed2cd37d3d991650bb88441.tar.gz
rneovim-b2277a42790907424ed2cd37d3d991650bb88441.tar.bz2
rneovim-b2277a42790907424ed2cd37d3d991650bb88441.zip
refactor(map): get rid of spurious subsystem_init() functions due to maps
-rw-r--r--src/nvim/api/private/helpers.c2
-rw-r--r--src/nvim/api/ui.c38
-rw-r--r--src/nvim/api/vim.c16
-rw-r--r--src/nvim/api/vim.h2
-rw-r--r--src/nvim/decoration.c9
-rw-r--r--src/nvim/main.c3
6 files changed, 25 insertions, 45 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 3ec6151090..92c06befc3 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -1725,7 +1725,7 @@ const char *describe_ns(NS ns_id)
{
String name;
handle_T id;
- map_foreach(namespace_ids, name, id, {
+ map_foreach((&namespace_ids), name, id, {
if ((NS)id == ns_id && name.size) {
return name.data;
}
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 63e6ad883a..713980ca68 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -37,24 +37,18 @@ typedef struct {
bool wildmenu_active;
} UIData;
-static PMap(uint64_t) *connected_uis = NULL;
-
-void remote_ui_init(void)
- FUNC_API_NOEXPORT
-{
- connected_uis = pmap_new(uint64_t)();
-}
+static PMap(uint64_t) connected_uis = MAP_INIT;
void remote_ui_disconnect(uint64_t channel_id)
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) {
return;
}
UIData *data = ui->data;
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);
ui->data = NULL; // Flag UI as "stopped".
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,
- pmap_has(uint64_t)(connected_uis, CHAN_STDIO));
+ pmap_has(uint64_t)(&connected_uis, CHAN_STDIO));
}
/// 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)
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,
"UI already attached to channel: %" PRId64, channel_id);
return;
@@ -172,7 +166,7 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
data->wildmenu_active = false;
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);
}
@@ -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)
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,
"UI not attached to channel: %" PRId64, channel_id);
return;
@@ -208,7 +202,7 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
Integer height, Error *err)
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,
"UI not attached to channel: %" PRId64, channel_id);
return;
@@ -220,7 +214,7 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
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->height = (int)height;
ui_refresh();
@@ -230,12 +224,12 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
Object value, Error *error)
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,
"UI not attached to channel: %" PRId64, channel_id);
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);
}
@@ -310,7 +304,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width,
Integer height, Error *err)
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,
"UI not attached to channel: %" PRId64, channel_id);
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)
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,
"UI not attached to channel: %" PRId64, channel_id);
return;
@@ -339,7 +333,7 @@ void nvim_ui_pum_set_height(uint64_t channel_id, Integer height, Error *err)
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]) {
api_set_error(err, kErrorTypeValidation,
"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)
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,
"UI not attached to channel: %" PRId64, channel_id);
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]) {
api_set_error(err, kErrorTypeValidation,
"UI must support the ext_popupmenu option");
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 400dbb126c..5aed85ef08 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -58,22 +58,16 @@
# include "api/vim.c.generated.h"
#endif
-void api_vim_init(void)
- FUNC_API_NOEXPORT
-{
- namespace_ids = map_new(String, handle_T)();
-}
-
void api_vim_free_all_mem(void)
FUNC_API_NOEXPORT
{
String name;
handle_T id;
- map_foreach(namespace_ids, name, id, {
+ map_foreach((&namespace_ids), name, id, {
(void)id;
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
@@ -1568,14 +1562,14 @@ void nvim_set_current_tabpage(Tabpage tabpage, Error *err)
Integer nvim_create_namespace(String name)
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) {
return id;
}
id = next_namespace_id++;
if (name.size > 0) {
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;
}
@@ -1590,7 +1584,7 @@ Dictionary nvim_get_namespaces(void)
String name;
handle_T id;
- map_foreach(namespace_ids, name, id, {
+ map_foreach((&namespace_ids), name, id, {
PUT(retval, name.data, INTEGER_OBJ(id));
})
diff --git a/src/nvim/api/vim.h b/src/nvim/api/vim.h
index d6873da6d2..4fd353ce5c 100644
--- a/src/nvim/api/vim.h
+++ b/src/nvim/api/vim.h
@@ -6,7 +6,7 @@
#include "nvim/api/private/defs.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);
#ifdef INCLUDE_GENERATED_DECLARATIONS
diff --git a/src/nvim/decoration.c b/src/nvim/decoration.c
index 062896fff4..5168ed6d0f 100644
--- a/src/nvim/decoration.c
+++ b/src/nvim/decoration.c
@@ -13,12 +13,7 @@
# include "decoration.c.generated.h"
#endif
-static PMap(uint64_t) *hl_decors;
-
-void decor_init(void)
-{
- hl_decors = pmap_new(uint64_t)();
-}
+static PMap(uint64_t) hl_decors;
/// Add highlighting to a buffer, bounded by two cursor positions,
/// with an offset.
@@ -77,7 +72,7 @@ void bufhl_add_hl_pos_offset(buf_T *buf,
Decoration *decor_hl(int hl_id)
{
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);
if (*dp) {
return *dp;
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 2cdf01b146..048bf877b5 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -126,8 +126,6 @@ void event_init(void)
signal_init();
// finish mspgack-rpc initialization
channel_init();
- remote_ui_init();
- api_vim_init();
terminal_init();
ui_init();
}
@@ -161,7 +159,6 @@ void early_init(mparm_T *paramp)
env_init();
fs_init();
handle_init();
- decor_init();
eval_init(); // init global variables
init_path(argv0 ? argv0 : "nvim");
init_normal_cmds(); // Init the table of Normal mode commands.