diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-06-21 16:53:47 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-06-21 18:40:35 +0200 |
commit | 8cd94e3bc06f43e73c5567b7db5cb37c164e28b8 (patch) | |
tree | 2bddc970fec6e3c62d6b8285b257ef2c9e1a72a5 | |
parent | a9442c532e9af45fc5c79d0207ab837cb715941f (diff) | |
download | rneovim-8cd94e3bc06f43e73c5567b7db5cb37c164e28b8.tar.gz rneovim-8cd94e3bc06f43e73c5567b7db5cb37c164e28b8.tar.bz2 rneovim-8cd94e3bc06f43e73c5567b7db5cb37c164e28b8.zip |
perf(ui): remove spurious allocations from mode_style_array()
-rw-r--r-- | src/nvim/cursor_shape.c | 42 | ||||
-rw-r--r-- | src/nvim/ui.c | 6 |
2 files changed, 26 insertions, 22 deletions
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c index 0248c25dfa..c7c7e6ae58 100644 --- a/src/nvim/cursor_shape.c +++ b/src/nvim/cursor_shape.c @@ -43,43 +43,45 @@ cursorentry_T shape_table[SHAPE_IDX_COUNT] = }; /// Converts cursor_shapes into an Array of Dictionaries +/// @param arena initialized arena where memory will be alocated +/// /// @return Array of the form {[ "cursor_shape": ... ], ...} -Array mode_style_array(void) +Array mode_style_array(Arena *arena) { - Array all = ARRAY_DICT_INIT; + Array all = arena_array(arena, SHAPE_IDX_COUNT); for (int i = 0; i < SHAPE_IDX_COUNT; i++) { - Dictionary dic = ARRAY_DICT_INIT; cursorentry_T *cur = &shape_table[i]; + Dictionary dic = arena_dict(arena, 3 + ((cur->used_for & SHAPE_CURSOR) ? 9 : 0)); + PUT_C(dic, "name", STRING_OBJ(cstr_as_string(cur->full_name))); + PUT_C(dic, "short_name", STRING_OBJ(cstr_as_string(cur->name))); if (cur->used_for & SHAPE_MOUSE) { - PUT(dic, "mouse_shape", INTEGER_OBJ(cur->mshape)); + PUT_C(dic, "mouse_shape", INTEGER_OBJ(cur->mshape)); } if (cur->used_for & SHAPE_CURSOR) { String shape_str; switch (cur->shape) { case SHAPE_BLOCK: - shape_str = cstr_to_string("block"); break; + shape_str = cstr_as_string("block"); break; case SHAPE_VER: - shape_str = cstr_to_string("vertical"); break; + shape_str = cstr_as_string("vertical"); break; case SHAPE_HOR: - shape_str = cstr_to_string("horizontal"); break; + shape_str = cstr_as_string("horizontal"); break; default: - shape_str = cstr_to_string("unknown"); + shape_str = cstr_as_string("unknown"); } - PUT(dic, "cursor_shape", STRING_OBJ(shape_str)); - PUT(dic, "cell_percentage", INTEGER_OBJ(cur->percentage)); - PUT(dic, "blinkwait", INTEGER_OBJ(cur->blinkwait)); - PUT(dic, "blinkon", INTEGER_OBJ(cur->blinkon)); - PUT(dic, "blinkoff", INTEGER_OBJ(cur->blinkoff)); - PUT(dic, "hl_id", INTEGER_OBJ(cur->id)); - PUT(dic, "id_lm", INTEGER_OBJ(cur->id_lm)); - PUT(dic, "attr_id", INTEGER_OBJ(cur->id ? syn_id2attr(cur->id) : 0)); - PUT(dic, "attr_id_lm", INTEGER_OBJ(cur->id_lm ? syn_id2attr(cur->id_lm) : 0)); + PUT_C(dic, "cursor_shape", STRING_OBJ(shape_str)); + PUT_C(dic, "cell_percentage", INTEGER_OBJ(cur->percentage)); + PUT_C(dic, "blinkwait", INTEGER_OBJ(cur->blinkwait)); + PUT_C(dic, "blinkon", INTEGER_OBJ(cur->blinkon)); + PUT_C(dic, "blinkoff", INTEGER_OBJ(cur->blinkoff)); + PUT_C(dic, "hl_id", INTEGER_OBJ(cur->id)); + PUT_C(dic, "id_lm", INTEGER_OBJ(cur->id_lm)); + PUT_C(dic, "attr_id", INTEGER_OBJ(cur->id ? syn_id2attr(cur->id) : 0)); + PUT_C(dic, "attr_id_lm", INTEGER_OBJ(cur->id_lm ? syn_id2attr(cur->id_lm) : 0)); } - PUT(dic, "name", STRING_OBJ(cstr_to_string(cur->full_name))); - PUT(dic, "short_name", STRING_OBJ(cstr_to_string(cur->name))); - ADD(all, DICTIONARY_OBJ(dic)); + ADD_C(all, DICTIONARY_OBJ(dic)); } return all; diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 0ac7f4a55f..96ce2c4cb1 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -507,10 +507,12 @@ void ui_flush(void) pending_cursor_update = false; } if (pending_mode_info_update) { - Array style = mode_style_array(); + Arena arena = ARENA_EMPTY; + arena_start(&arena, &ui_ext_fixblk); + Array style = mode_style_array(&arena); bool enabled = (*p_guicursor != NUL); ui_call_mode_info_set(enabled, style); - api_free_array(style); + arena_mem_free(arena_finish(&arena), &ui_ext_fixblk); pending_mode_info_update = false; } if (pending_mode_update && !starting) { |