aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/ui.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-06-25 18:51:55 +0200
committerbfredl <bjorn.linse@gmail.com>2022-07-18 14:08:44 +0200
commit45bee1dafd0d4042f3b22928b5cc6021a1772bb7 (patch)
tree81f421dbba4250db47c0a307654727fa238a5316 /src/nvim/api/ui.c
parent67a04fe6cb0f6b0cd3d44ae37b7caddddda198ea (diff)
downloadrneovim-45bee1dafd0d4042f3b22928b5cc6021a1772bb7.tar.gz
rneovim-45bee1dafd0d4042f3b22928b5cc6021a1772bb7.tar.bz2
rneovim-45bee1dafd0d4042f3b22928b5cc6021a1772bb7.zip
perf(ui): eliminate spurious memory allocations for hl_attr_define event
Diffstat (limited to 'src/nvim/api/ui.c')
-rw-r--r--src/nvim/api/ui.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index 54ce838b9b..aa7bed1132 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -748,8 +748,10 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt
UIData *data = ui->data;
Array args = data->call_buf;
ADD_C(args, INTEGER_OBJ(id));
- ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(rgb_attrs, true)));
- ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(cterm_attrs, false)));
+ MAXSIZE_TEMP_DICT(rgb, 16);
+ MAXSIZE_TEMP_DICT(cterm, 16);
+ ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&rgb, rgb_attrs, true)));
+ ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&cterm, cterm_attrs, false)));
if (ui->ui_ext[kUIHlState]) {
ADD_C(args, ARRAY_OBJ(info));
@@ -758,9 +760,6 @@ static void remote_ui_hl_attr_define(UI *ui, Integer id, HlAttrs rgb_attrs, HlAt
}
push_call(ui, "hl_attr_define", args);
- // TODO(bfredl): could be elided
- api_free_dictionary(kv_A(args, 1).data.dictionary);
- api_free_dictionary(kv_A(args, 2).data.dictionary);
}
static void remote_ui_highlight_set(UI *ui, int id)
@@ -772,11 +771,9 @@ static void remote_ui_highlight_set(UI *ui, int id)
return;
}
data->hl_id = id;
- Dictionary hl = hlattrs2dict(syn_attr2entry(id), ui->rgb);
-
- ADD_C(args, DICTIONARY_OBJ(hl));
+ MAXSIZE_TEMP_DICT(dict, 16);
+ ADD_C(args, DICTIONARY_OBJ(hlattrs2dict(&dict, syn_attr2entry(id), ui->rgb)));
push_call(ui, "highlight_set", args);
- api_free_dictionary(kv_A(args, 0).data.dictionary);
}
/// "true" cursor used only for input focus
@@ -963,7 +960,7 @@ static Array translate_contents(UI *ui, Array contents)
Array new_item = ARRAY_DICT_INIT;
int attr = (int)item.items[0].data.integer;
if (attr) {
- Dictionary rgb_attrs = hlattrs2dict(syn_attr2entry(attr), ui->rgb);
+ Dictionary rgb_attrs = hlattrs2dict(NULL, syn_attr2entry(attr), ui->rgb);
ADD(new_item, DICTIONARY_OBJ(rgb_attrs));
} else {
ADD(new_item, DICTIONARY_OBJ((Dictionary)ARRAY_DICT_INIT));