aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2021-08-22 16:03:21 +0200
committerBjörn Linse <bjorn.linse@gmail.com>2021-08-22 16:15:38 +0200
commitde21e6ef3d9af96d2b71e54d8148d28b5fc9f22e (patch)
treedc153c0cf6ac08e6f0f5508dcc2603618f314ef6 /src/nvim/api
parentdb1b0ee3b30fd4cd323907c7f24bd575c22e68f0 (diff)
downloadrneovim-de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e.tar.gz
rneovim-de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e.tar.bz2
rneovim-de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e.zip
refactor(map): remove extra-allocating map_new/map_free functions
Note: the reason for removing them is not that there after this refactor is no use of them, but rather that having them available is an anti-pattern: they manange an _extra_ heap allocation which has nothing to do with the functionality of the map itself (khash manages the real buffers internally). In case there happens to be a reason to allocate the map structure itself later, this should be made explicit using xcalloc/xfree calls.
Diffstat (limited to 'src/nvim/api')
-rw-r--r--src/nvim/api/private/dispatch.c6
-rw-r--r--src/nvim/api/private/helpers.c2
-rw-r--r--src/nvim/api/vim.c4
3 files changed, 6 insertions, 6 deletions
diff --git a/src/nvim/api/private/dispatch.c b/src/nvim/api/private/dispatch.c
index eae4581f42..9f16da4078 100644
--- a/src/nvim/api/private/dispatch.c
+++ b/src/nvim/api/private/dispatch.c
@@ -21,12 +21,12 @@
#include "nvim/api/window.h"
#include "nvim/api/deprecated.h"
-static Map(String, MsgpackRpcRequestHandler) *methods = NULL;
+static Map(String, MsgpackRpcRequestHandler) methods = MAP_INIT;
static void msgpack_rpc_add_method_handler(String method,
MsgpackRpcRequestHandler handler)
{
- map_put(String, MsgpackRpcRequestHandler)(methods, method, handler);
+ map_put(String, MsgpackRpcRequestHandler)(&methods, method, handler);
}
/// @param name API method name
@@ -37,7 +37,7 @@ MsgpackRpcRequestHandler msgpack_rpc_get_handler_for(const char *name,
{
String m = { .data = (char *)name, .size = name_len };
MsgpackRpcRequestHandler rv =
- map_get(String, MsgpackRpcRequestHandler)(methods, m);
+ map_get(String, MsgpackRpcRequestHandler)(&methods, m);
if (!rv.fn) {
api_set_error(error, kErrorTypeException, "Invalid method: %.*s",
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 6114500277..eedcfd69b8 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -1724,7 +1724,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/vim.c b/src/nvim/api/vim.c
index 5aed85ef08..90c43a1b04 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -63,7 +63,7 @@ void api_vim_free_all_mem(void)
{
String name;
handle_T id;
- map_foreach((&namespace_ids), name, id, {
+ map_foreach(&namespace_ids, name, id, {
(void)id;
xfree(name.data);
})
@@ -1584,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));
})