mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 21:48:35 +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:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user