aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/tui
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2023-01-03 15:24:41 +0100
committerbfredl <bjorn.linse@gmail.com>2023-01-03 17:31:54 +0100
commitb2295ac4ec80e141628cea33ebee81c96e168989 (patch)
treeee197c75d19b1922d9a1149f8b5e1b7a12a76c70 /src/nvim/tui
parent5b22b32e50858b781eb2658ba099eaffaa5ea13b (diff)
downloadrneovim-b2295ac4ec80e141628cea33ebee81c96e168989.tar.gz
rneovim-b2295ac4ec80e141628cea33ebee81c96e168989.tar.bz2
rneovim-b2295ac4ec80e141628cea33ebee81c96e168989.zip
refactor(api): do not allocate temporaries for internal events
Diffstat (limited to 'src/nvim/tui')
-rw-r--r--src/nvim/tui/input.c24
-rw-r--r--src/nvim/tui/tui.c7
2 files changed, 16 insertions, 15 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c
index c6066597f0..b837a380d5 100644
--- a/src/nvim/tui/input.c
+++ b/src/nvim/tui/input.c
@@ -220,11 +220,12 @@ static void tinput_wait_enqueue(void **argv)
const size_t len = rbuffer_size(input->key_buffer);
String keys = { .data = xmallocz(len), .size = len };
rbuffer_read(input->key_buffer, keys.data, len);
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(keys)); // 'data'
- ADD(args, BOOLEAN_OBJ(true)); // 'crlf'
- ADD(args, INTEGER_OBJ(input->paste)); // 'phase'
+ MAXSIZE_TEMP_ARRAY(args, 3);
+ ADD_C(args, STRING_OBJ(keys)); // 'data'
+ ADD_C(args, BOOLEAN_OBJ(true)); // 'crlf'
+ ADD_C(args, INTEGER_OBJ(input->paste)); // 'phase'
rpc_send_event(ui_client_channel_id, "nvim_paste", args);
+ api_free_string(keys);
if (input->paste == 1) {
// Paste phase: "continue"
input->paste = 2;
@@ -233,8 +234,8 @@ static void tinput_wait_enqueue(void **argv)
} else { // enqueue input for the main thread or Nvim server
RBUFFER_UNTIL_EMPTY(input->key_buffer, buf, len) {
const String keys = { .data = buf, .size = len };
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(copy_string(keys, NULL)));
+ MAXSIZE_TEMP_ARRAY(args, 1);
+ ADD_C(args, STRING_OBJ(keys));
// NOTE: This is non-blocking and won't check partially processed input,
// but should be fine as all big sends are handled with nvim_paste, not nvim_input
rpc_send_event(ui_client_channel_id, "nvim_input", args);
@@ -529,8 +530,8 @@ static bool handle_focus_event(TermInput *input)
// Advance past the sequence
rbuffer_consumed(input->read_stream.buffer, 3);
- Array args = ARRAY_DICT_INIT;
- ADD(args, BOOLEAN_OBJ(focus_gained));
+ MAXSIZE_TEMP_ARRAY(args, 1);
+ ADD_C(args, BOOLEAN_OBJ(focus_gained));
rpc_send_event(ui_client_channel_id, "nvim_ui_set_focus", args);
return true;
}
@@ -581,10 +582,9 @@ static HandleState handle_bracketed_paste(TermInput *input)
static void set_bg(char *bgvalue)
{
if (ui_client_attached) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_to_string("term_background")));
- ADD(args, STRING_OBJ(cstr_as_string(xstrdup(bgvalue))));
-
+ MAXSIZE_TEMP_ARRAY(args, 2);
+ ADD_C(args, STRING_OBJ(cstr_as_string("term_background")));
+ ADD_C(args, STRING_OBJ(cstr_as_string(bgvalue)));
rpc_send_event(ui_client_channel_id, "nvim_ui_set_option", args);
}
}
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 0d01cd44cd..3205547324 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -1401,6 +1401,7 @@ static void show_verbose_terminfo(TUIData *data)
PUT(opts, "verbose", BOOLEAN_OBJ(true));
ADD(args, DICTIONARY_OBJ(opts));
rpc_send_event(ui_client_channel_id, "nvim_echo", args);
+ api_free_array(args);
}
#ifdef UNIX
@@ -1493,9 +1494,9 @@ static void tui_option_set(UI *ui, String name, Object value)
invalidate(ui, 0, data->grid.height, 0, data->grid.width);
if (ui_client_channel_id) {
- Array args = ARRAY_DICT_INIT;
- ADD(args, STRING_OBJ(cstr_as_string(xstrdup("rgb"))));
- ADD(args, BOOLEAN_OBJ(value.data.boolean));
+ MAXSIZE_TEMP_ARRAY(args, 2);
+ ADD_C(args, STRING_OBJ(cstr_as_string("rgb")));
+ ADD_C(args, BOOLEAN_OBJ(value.data.boolean));
rpc_send_event(ui_client_channel_id, "nvim_ui_set_option", args);
}
} else if (strequal(name.data, "ttimeout")) {