mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 20:18:32 +00:00
vim-patch:9.1.0824: too many strlen() calls in register.c (#31022)
Problem: too many strlen() calls in register.c
Solution: refactor code, add string_T struct to keep track
of string lengths (John Marriott)
closes: vim/vim#15952
79f6ffd388
Co-authored-by: John Marriott <basilisk@internode.on.net>
This commit is contained in:
@@ -111,6 +111,12 @@ typedef kvec_withinit_t(Object, 16) ArrayBuilder;
|
||||
#define STATIC_CSTR_AS_OBJ(s) STRING_OBJ(STATIC_CSTR_AS_STRING(s))
|
||||
#define STATIC_CSTR_TO_OBJ(s) STRING_OBJ(STATIC_CSTR_TO_STRING(s))
|
||||
|
||||
#define API_CLEAR_STRING(s) \
|
||||
do { \
|
||||
XFREE_CLEAR(s.data); \
|
||||
s.size = 0; \
|
||||
} while (0)
|
||||
|
||||
// Helpers used by the generated msgpack-rpc api wrappers
|
||||
#define api_init_boolean
|
||||
#define api_init_integer
|
||||
|
@@ -1317,15 +1317,15 @@ void nvim_put(ArrayOf(String) lines, String type, Boolean after, Boolean follow,
|
||||
return; // Nothing to do.
|
||||
}
|
||||
|
||||
reg->y_array = arena_alloc(arena, lines.size * sizeof(uint8_t *), true);
|
||||
reg->y_array = arena_alloc(arena, lines.size * sizeof(String), true);
|
||||
reg->y_size = lines.size;
|
||||
for (size_t i = 0; i < lines.size; i++) {
|
||||
VALIDATE_T("line", kObjectTypeString, lines.items[i].type, {
|
||||
return;
|
||||
});
|
||||
String line = lines.items[i].data.string;
|
||||
reg->y_array[i] = arena_memdupz(arena, line.data, line.size);
|
||||
memchrsub(reg->y_array[i], NUL, NL, line.size);
|
||||
reg->y_array[i] = copy_string(line, arena);
|
||||
memchrsub(reg->y_array[i].data, NUL, NL, line.size);
|
||||
}
|
||||
|
||||
finish_yankreg_from_object(reg, false);
|
||||
|
Reference in New Issue
Block a user