diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-06-08 22:02:02 +0200 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2022-06-20 12:44:56 +0200 |
commit | 5d6987210578f5f1c3151988b99a9411f9603374 (patch) | |
tree | c8d1b70ef948a4beafe82195431f1c6607fbe8b7 /src/nvim/api/private/helpers.c | |
parent | b2ed439bd5ab1b431bb61f8754554c48453495c5 (diff) | |
download | rneovim-5d6987210578f5f1c3151988b99a9411f9603374.tar.gz rneovim-5d6987210578f5f1c3151988b99a9411f9603374.tar.bz2 rneovim-5d6987210578f5f1c3151988b99a9411f9603374.zip |
perf(ui): reduce allocation overhead when encoding "redraw" events
Note for external UIs: Nvim can now emit multiple "redraw" event batches
before a final "flush" event is received. To retain existing behavior,
clients should make sure to update visible state at an explicit "flush"
event, not just the end of a "redraw" batch of event.
* Get rid of copy_object() blizzard in the auto-generated ui_event layer
* Special case "grid_line" by encoding screen state directly to
msgpack events with no intermediate API events.
* Get rid of the arcane notion of referring to the screen as the "shell"
* Array and Dictionary are kvec_t:s, so define them as such.
* Allow kvec_t:s, such as Arrays and Dictionaries, to be allocated with
a predetermined size within an arena.
* Eliminate redundant capacity checking when filling such kvec_t:s
with values.
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index ff6a4c37e8..693d946088 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -669,6 +669,32 @@ void api_free_string(String value) xfree(value.data); } +Array arena_array(Arena *arena, size_t max_size) +{ + Array arr = ARRAY_DICT_INIT; + kv_fixsize_arena(arena, arr, max_size); + return arr; +} + +Dictionary arena_dict(Arena *arena, size_t max_size) +{ + Dictionary dict = ARRAY_DICT_INIT; + kv_fixsize_arena(arena, dict, max_size); + return dict; +} + +String arena_string(Arena *arena, String str) +{ + if (str.size) { + char *mem = arena_alloc(arena, str.size + 1, false); + memcpy(mem, str.data, str.size); + mem[str.size] = NUL; + return cbuf_as_string(mem, str.size); + } else { + return (String)STRING_INIT; + } +} + void api_free_object(Object value) { switch (value.type) { |