aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.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/api/vim.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/api/vim.c')
-rw-r--r--src/nvim/api/vim.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index e472f5d160..c6043a2871 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -675,21 +675,21 @@ String nvim_get_current_line(Arena *arena, Error *err)
///
/// @param line Line contents
/// @param[out] err Error details, if any
-void nvim_set_current_line(String line, Error *err)
+void nvim_set_current_line(String line, Arena *arena, Error *err)
FUNC_API_SINCE(1)
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
{
- buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, err);
+ buffer_set_line(curbuf->handle, curwin->w_cursor.lnum - 1, line, arena, err);
}
/// Deletes the current line.
///
/// @param[out] err Error details, if any
-void nvim_del_current_line(Error *err)
+void nvim_del_current_line(Arena *arena, Error *err)
FUNC_API_SINCE(1)
FUNC_API_TEXTLOCK_ALLOW_CMDWIN
{
- buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, err);
+ buffer_del_line(curbuf->handle, curwin->w_cursor.lnum - 1, arena, err);
}
/// Gets a global (g:) variable.