diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 16:03:21 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-08-22 16:15:38 +0200 |
commit | de21e6ef3d9af96d2b71e54d8148d28b5fc9f22e (patch) | |
tree | dc153c0cf6ac08e6f0f5508dcc2603618f314ef6 /src/nvim/channel.c | |
parent | db1b0ee3b30fd4cd323907c7f24bd575c22e68f0 (diff) | |
download | rneovim-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/channel.c')
-rw-r--r-- | src/nvim/channel.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 0cab916c45..6f12d2eab8 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -32,13 +32,9 @@ static uint64_t next_chan_id = CHAN_STDERR+1; /// Teardown the module void channel_teardown(void) { - if (!channels) { - return; - } - Channel *channel; - map_foreach_value(channels, channel, { + map_foreach_value(&channels, channel, { channel_close(channel->id, kChannelPartAll, NULL); }); } @@ -152,7 +148,6 @@ bool channel_close(uint64_t id, ChannelPart part, const char **error) /// Initializes the module void channel_init(void) { - channels = pmap_new(uint64_t)(); channel_alloc(kChannelStreamStderr); rpc_init(); } @@ -177,7 +172,7 @@ Channel *channel_alloc(ChannelStreamType type) chan->exit_status = -1; chan->streamtype = type; assert(chan->id <= VARNUMBER_MAX); - pmap_put(uint64_t)(channels, chan->id, chan); + pmap_put(uint64_t)(&channels, chan->id, chan); return chan; } @@ -249,7 +244,7 @@ static void free_channel_event(void **argv) callback_reader_free(&chan->on_stderr); callback_free(&chan->on_exit); - pmap_del(uint64_t)(channels, chan->id); + pmap_del(uint64_t)(&channels, chan->id); multiqueue_free(chan->events); xfree(chan); } @@ -259,7 +254,7 @@ static void channel_destroy_early(Channel *chan) if ((chan->id != --next_chan_id)) { abort(); } - pmap_del(uint64_t)(channels, chan->id); + pmap_del(uint64_t)(&channels, chan->id); chan->id = 0; if ((--chan->refcount != 0)) { @@ -899,7 +894,7 @@ Array channel_all_info(void) { Channel *channel; Array ret = ARRAY_DICT_INIT; - map_foreach_value(channels, channel, { + map_foreach_value(&channels, channel, { ADD(ret, DICTIONARY_OBJ(channel_info(channel->id))); }); return ret; |