mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
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.
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user