perf(ui): eliminate spurious memory allocations for hl_attr_define event

This commit is contained in:
bfredl
2022-06-25 18:51:55 +02:00
parent 67a04fe6cb
commit 45bee1dafd
7 changed files with 58 additions and 38 deletions

View File

@@ -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));