aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/runtime.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-02-19 12:00:26 +0100
committerbfredl <bjorn.linse@gmail.com>2024-02-20 11:24:15 +0100
commitf2c73e9ee2bd094f21f55dc97c5ad8d2f3a51621 (patch)
tree23e28db7aa89921f2fc17d315926d6e473f099e0 /src/nvim/runtime.c
parent8952a89db588db10a9dba16356f9bbd35ca5fabb (diff)
downloadrneovim-f2c73e9ee2bd094f21f55dc97c5ad8d2f3a51621.tar.gz
rneovim-f2c73e9ee2bd094f21f55dc97c5ad8d2f3a51621.tar.bz2
rneovim-f2c73e9ee2bd094f21f55dc97c5ad8d2f3a51621.zip
refactor(api): reduce temporary allocations when replacing lines
The way ml_replace_buf is implemented makes it unfriendly for being used in a loop: every call allocates a scratch buffer for putting the line into the "dirty" state. This then immediately needs to be freed as the next ml_replace_buf and/or ml_append_buf call will flush that buffer. It's better to later pay the price of allocating the scratch buffer only if the line is being immediately edited (likely when using the API to only change one line) with an extra memcpy, than allocating that buffer multiple times every time the API is called. Of course, a separate xmalloc/xfree cycle for each time the dirty line changes is unwanted to begin with. But fixing that is a later refactor.
Diffstat (limited to 'src/nvim/runtime.c')
-rw-r--r--src/nvim/runtime.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index fb6397f9eb..76188499e3 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -581,7 +581,7 @@ Array runtime_inspect(Arena *arena)
for (size_t i = 0; i < kv_size(path); i++) {
SearchPathItem *item = &kv_A(path, i);
- Array entry = ARRAY_DICT_INIT;
+ Array entry = arena_array(arena, 3);
ADD_C(entry, CSTR_AS_OBJ(item->path));
ADD_C(entry, BOOLEAN_OBJ(item->after));
if (item->has_lua != kNone) {