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:
zeertzjq
2024-11-01 17:34:19 +08:00
committed by GitHub
parent 9b357e30fd
commit cbd8b2c162
6 changed files with 152 additions and 126 deletions

View File

@@ -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

View File

@@ -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);