diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 11:25:59 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 11:28:47 +0200 |
commit | c265fd31ab2b0307650ad94e1ea272e9360c345f (patch) | |
tree | 9ca3efcc04236190d15a418e1ff0a2ca1d4d6a1c | |
parent | b888018aed249174aad7586859ac5142f1a3ef10 (diff) | |
download | rneovim-c265fd31ab2b0307650ad94e1ea272e9360c345f.tar.gz rneovim-c265fd31ab2b0307650ad94e1ea272e9360c345f.tar.bz2 rneovim-c265fd31ab2b0307650ad94e1ea272e9360c345f.zip |
refactor(api): remove unneccesary indirection around handles
These things are just maps to pointers, no need to perform
a huge song and dance around it.
-rw-r--r-- | src/nvim/api/private/handle.c | 40 | ||||
-rw-r--r-- | src/nvim/api/private/handle.h | 24 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.c | 1 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.h | 8 | ||||
-rw-r--r-- | src/nvim/autocmd.c | 6 | ||||
-rw-r--r-- | src/nvim/buffer.c | 5 | ||||
-rw-r--r-- | src/nvim/fileio.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 1 | ||||
-rw-r--r-- | src/nvim/lua/executor.c | 1 | ||||
-rw-r--r-- | src/nvim/lua/treesitter.c | 2 | ||||
-rw-r--r-- | src/nvim/main.c | 2 | ||||
-rw-r--r-- | src/nvim/os_unix.c | 1 | ||||
-rw-r--r-- | src/nvim/terminal.c | 1 | ||||
-rw-r--r-- | src/nvim/window.c | 9 |
14 files changed, 19 insertions, 84 deletions
diff --git a/src/nvim/api/private/handle.c b/src/nvim/api/private/handle.c deleted file mode 100644 index eb96192af2..0000000000 --- a/src/nvim/api/private/handle.c +++ /dev/null @@ -1,40 +0,0 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - -#include <assert.h> -#include <stdint.h> - -#include "nvim/vim.h" -#include "nvim/map.h" -#include "nvim/api/private/handle.h" - -#define HANDLE_INIT(name) name##_handles = pmap_new(handle_T)() - -#define HANDLE_IMPL(type, name) \ - static PMap(handle_T) *name##_handles = NULL; /* NOLINT */ \ - \ - type *handle_get_##name(handle_T handle) \ - { \ - return pmap_get(handle_T)(name##_handles, handle); \ - } \ - \ - void handle_register_##name(type *name) \ - { \ - pmap_put(handle_T)(name##_handles, name->handle, name); \ - } \ - \ - void handle_unregister_##name(type *name) \ - { \ - pmap_del(handle_T)(name##_handles, name->handle); \ - } - -HANDLE_IMPL(buf_T, buffer) -HANDLE_IMPL(win_T, window) -HANDLE_IMPL(tabpage_T, tabpage) - -void handle_init(void) -{ - HANDLE_INIT(buffer); - HANDLE_INIT(window); - HANDLE_INIT(tabpage); -} diff --git a/src/nvim/api/private/handle.h b/src/nvim/api/private/handle.h deleted file mode 100644 index 26e9dc3314..0000000000 --- a/src/nvim/api/private/handle.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef NVIM_API_PRIVATE_HANDLE_H -#define NVIM_API_PRIVATE_HANDLE_H - -#include "nvim/vim.h" -#include "nvim/buffer_defs.h" -#include "nvim/api/private/defs.h" - -#define HANDLE_DECLS(type, name) \ - type *handle_get_##name(handle_T handle); \ - void handle_register_##name(type *name); \ - void handle_unregister_##name(type *name); - -// handle_get_buffer handle_register_buffer, handle_unregister_buffer -HANDLE_DECLS(buf_T, buffer) -// handle_get_window handle_register_window, handle_unregister_window -HANDLE_DECLS(win_T, window) -// handle_get_tabpage handle_register_tabpage, handle_unregister_tabpage -HANDLE_DECLS(tabpage_T, tabpage) - -void handle_init(void); - - -#endif // NVIM_API_PRIVATE_HANDLE_H - diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 92c06befc3..6114500277 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -9,7 +9,6 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/private/defs.h" -#include "nvim/api/private/handle.h" #include "nvim/api/vim.h" #include "nvim/msgpack_rpc/helpers.h" #include "nvim/lua/executor.h" diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index 055abb797f..ecce6afa26 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -101,6 +101,14 @@ #define api_free_window(value) #define api_free_tabpage(value) +EXTERN PMap(handle_T) buffer_handles INIT(= MAP_INIT); +EXTERN PMap(handle_T) window_handles INIT(= MAP_INIT); +EXTERN PMap(handle_T) tabpage_handles INIT(= MAP_INIT); + +#define handle_get_buffer(h) pmap_get(handle_T)(&buffer_handles, (h)) +#define handle_get_window(h) pmap_get(handle_T)(&window_handles, (h)) +#define handle_get_tabpage(h) pmap_get(handle_T)(&tabpage_handles, (h)) + /// Structure used for saving state for :try /// /// Used when caller is supposed to be operating when other VimL code is being diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c index bec9808183..417953eb14 100644 --- a/src/nvim/autocmd.c +++ b/src/nvim/autocmd.c @@ -5,7 +5,7 @@ #include "nvim/autocmd.h" -#include "nvim/api/private/handle.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -1150,7 +1150,7 @@ void aucmd_prepbuf(aco_save_T *aco, buf_T *buf) block_autocmds(); // We don't want BufEnter/WinEnter autocommands. if (need_append) { win_append(lastwin, aucmd_win); - handle_register_window(aucmd_win); + pmap_put(handle_T)(&window_handles, aucmd_win->handle, aucmd_win); win_config_float(aucmd_win, aucmd_win->w_float_config); } // Prevent chdir() call in win_enter_ext(), through do_autochdir() @@ -1191,7 +1191,7 @@ void aucmd_restbuf(aco_save_T *aco) win_found: win_remove(curwin, NULL); - handle_unregister_window(curwin); + pmap_del(handle_T)(&window_handles, curwin->handle); if (curwin->w_grid_alloc.chars != NULL) { ui_comp_remove_grid(&curwin->w_grid_alloc); ui_call_win_hide(curwin->w_grid_alloc.handle); diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a7fc34f2d6..fdb3ffdc7e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -24,7 +24,6 @@ #include <inttypes.h> #include <assert.h> -#include "nvim/api/private/handle.h" #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/ascii.h" @@ -757,7 +756,7 @@ void buf_freeall(buf_T *buf, int flags) */ static void free_buffer(buf_T *buf) { - handle_unregister_buffer(buf); + pmap_del(handle_T)(&buffer_handles, buf->b_fnum); buf_free_count++; // b:changedtick uses an item in buf_T. free_buffer_stuff(buf, kBffClearWinInfo); @@ -1841,7 +1840,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, lastbuf = buf; buf->b_fnum = top_file_num++; - handle_register_buffer(buf); + pmap_put(handle_T)(&buffer_handles, buf->b_fnum, buf); if (top_file_num < 0) { // wrap around (may cause duplicates) EMSG(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0) { diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ee8be8429f..3d058e1d09 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -11,7 +11,7 @@ #include <fcntl.h> #include "nvim/vim.h" -#include "nvim/api/private/handle.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/fileio.h" #include "nvim/buffer.h" diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 2b6c5b9f37..28f58e2c34 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -52,7 +52,6 @@ #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/fileio.h" -#include "nvim/api/private/handle.h" /// Index in scriptin diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 5799c3ee98..87f35a0595 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -13,7 +13,6 @@ #include "nvim/func_attr.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/private/handle.h" #include "nvim/api/vim.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/vim.h" diff --git a/src/nvim/lua/treesitter.c b/src/nvim/lua/treesitter.c index 1425baacf0..14fed0d474 100644 --- a/src/nvim/lua/treesitter.c +++ b/src/nvim/lua/treesitter.c @@ -18,7 +18,7 @@ #include "tree_sitter/api.h" #include "nvim/lua/treesitter.h" -#include "nvim/api/private/handle.h" +#include "nvim/api/private/helpers.h" #include "nvim/memline.h" #include "nvim/buffer.h" diff --git a/src/nvim/main.c b/src/nvim/main.c index 048bf877b5..9fc82a75af 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -78,7 +78,6 @@ #include "nvim/api/ui.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/private/handle.h" #include "nvim/api/private/dispatch.h" #ifndef WIN32 # include "nvim/os/pty_process_unix.h" @@ -158,7 +157,6 @@ void early_init(mparm_T *paramp) { env_init(); fs_init(); - handle_init(); eval_init(); // init global variables init_path(argv0 ? argv0 : "nvim"); init_normal_cmds(); // Init the table of Normal mode commands. diff --git a/src/nvim/os_unix.c b/src/nvim/os_unix.c index be4bd9709b..44274e8f1d 100644 --- a/src/nvim/os_unix.c +++ b/src/nvim/os_unix.c @@ -7,7 +7,6 @@ #include <stdbool.h> #include <string.h> -#include "nvim/api/private/handle.h" #include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/os_unix.h" diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 45419b8247..88dd9db6d1 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -76,7 +76,6 @@ #include "nvim/event/time.h" #include "nvim/os/input.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/private/handle.h" typedef struct terminal_state { VimState state; diff --git a/src/nvim/window.c b/src/nvim/window.c index fefbab822e..990064b33d 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -5,7 +5,6 @@ #include <inttypes.h> #include <stdbool.h> -#include "nvim/api/private/handle.h" #include "nvim/api/private/helpers.h" #include "nvim/vim.h" #include "nvim/ascii.h" @@ -3601,7 +3600,7 @@ static tabpage_T *alloc_tabpage(void) static int last_tp_handle = 0; tabpage_T *tp = xcalloc(1, sizeof(tabpage_T)); tp->handle = ++last_tp_handle; - handle_register_tabpage(tp); + pmap_put(handle_T)(&tabpage_handles, tp->handle, tp); // Init t: variables. tp->tp_vars = tv_dict_alloc(); @@ -3616,7 +3615,7 @@ void free_tabpage(tabpage_T *tp) { int idx; - handle_unregister_tabpage(tp); + pmap_del(handle_T)(&tabpage_handles, tp->handle); diff_clear(tp); for (idx = 0; idx < SNAP_COUNT; ++idx) clear_snapshot(tp, idx); @@ -4545,7 +4544,7 @@ static win_T *win_alloc(win_T *after, bool hidden) win_T *new_wp = xcalloc(1, sizeof(win_T)); new_wp->handle = ++last_win_id; - handle_register_window(new_wp); + pmap_put(handle_T)(&window_handles, new_wp->handle, new_wp); grid_assign_handle(&new_wp->w_grid_alloc); @@ -4616,7 +4615,7 @@ win_free ( int i; wininfo_T *wip; - handle_unregister_window(wp); + pmap_del(handle_T)(&window_handles, wp->handle); clearFolding(wp); /* reduce the reference count to the argument list. */ |