diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-11-14 18:04:36 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-14 18:04:36 +0000 |
commit | f8c671827710c6e9cca3bfd60c32098b2be8239a (patch) | |
tree | a5d949663a1b061ca82ecd89bb90f083f9a2bbb8 /src/nvim/buffer_updates.c | |
parent | 30604320072335122aea0f37890f136b2ba0e445 (diff) | |
download | rneovim-f8c671827710c6e9cca3bfd60c32098b2be8239a.tar.gz rneovim-f8c671827710c6e9cca3bfd60c32098b2be8239a.tar.bz2 rneovim-f8c671827710c6e9cca3bfd60c32098b2be8239a.zip |
feat(lua-api): avoid unnecessary allocations (#19877)
Lua makes (or reuses) an internal copy of strings, so we can safely push
buf pointers onto the stack.
Diffstat (limited to 'src/nvim/buffer_updates.c')
-rw-r--r-- | src/nvim/buffer_updates.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c index 1b3c0bc28f..681d5df047 100644 --- a/src/nvim/buffer_updates.c +++ b/src/nvim/buffer_updates.c @@ -1,6 +1,7 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +#include "nvim/api/buffer.h" #include "nvim/api/private/helpers.h" #include "nvim/assert.h" #include "nvim/buffer.h" @@ -34,12 +35,10 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb // count how many channels are currently watching the buffer size_t size = kv_size(buf->update_channels); - if (size) { - for (size_t i = 0; i < size; i++) { - if (kv_A(buf->update_channels, i) == channel_id) { - // buffer is already registered ... nothing to do - return true; - } + for (size_t i = 0; i < size; i++) { + if (kv_A(buf->update_channels, i) == channel_id) { + // buffer is already registered ... nothing to do + return true; } } @@ -69,7 +68,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, BufUpdateCallbacks cb linedata.size = line_count; linedata.items = xcalloc(line_count, sizeof(Object)); - buf_collect_lines(buf, line_count, 1, true, &linedata, NULL); + buf_collect_lines(buf, line_count, 1, true, &linedata, NULL, NULL); } args.items[4] = ARRAY_OBJ(linedata); @@ -231,7 +230,7 @@ void buf_updates_send_changes(buf_T *buf, linenr_T firstline, int64_t num_added, linedata.size = (size_t)num_added; linedata.items = xcalloc((size_t)num_added, sizeof(Object)); buf_collect_lines(buf, (size_t)num_added, firstline, true, &linedata, - NULL); + NULL, NULL); } args.items[4] = ARRAY_OBJ(linedata); args.items[5] = BOOLEAN_OBJ(false); |