diff options
author | zeertzjq <zeertzjq@outlook.com> | 2025-01-24 08:52:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-24 00:52:55 +0000 |
commit | 2470db02c5136525b8abce1ee0889d94f8d81d98 (patch) | |
tree | 07418e7e683c431f1e39a76c875fa53273d5410e /src/nvim/os/shell.c | |
parent | 8bc28978b632362ae658f8d4a6327e07a8b371b2 (diff) | |
download | rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.tar.gz rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.tar.bz2 rneovim-2470db02c5136525b8abce1ee0889d94f8d81d98.zip |
vim-patch:partial:9.1.1050: too many strlen() calls in os_unix.c (#32188)
Problem: too many strlen() calls in os_unix.c
Solution: refactor os_unix.c and remove calls to strlen()
(John Marriott)
closes: vim/vim#16496
https://github.com/vim/vim/commit/efc41a5958bf25b352e0916af5f57dafbbb44f17
Omit os_expand_wildcards() change: Nvim's code is more complicated and
harder to refactor.
Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat (limited to 'src/nvim/os/shell.c')
-rw-r--r-- | src/nvim/os/shell.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c index 5347c8db9a..d60d0b3e55 100644 --- a/src/nvim/os/shell.c +++ b/src/nvim/os/shell.c @@ -1208,10 +1208,11 @@ static void read_input(StringBuilder *buf) size_t len = 0; linenr_T lnum = curbuf->b_op_start.lnum; char *lp = ml_get(lnum); + size_t lplen = (size_t)ml_get_len(lnum); while (true) { - size_t l = strlen(lp + written); - if (l == 0) { + lplen -= written; + if (lplen == 0) { len = 0; } else if (lp[written] == NL) { // NL -> NUL translation @@ -1219,11 +1220,11 @@ static void read_input(StringBuilder *buf) kv_push(*buf, NUL); } else { char *s = vim_strchr(lp + written, NL); - len = s == NULL ? l : (size_t)(s - (lp + written)); + len = s == NULL ? lplen : (size_t)(s - (lp + written)); kv_concat_len(*buf, lp + written, len); } - if (len == l) { + if (len == lplen) { // Finished a line, add a NL, unless this line should not have one. if (lnum != curbuf->b_op_end.lnum || (!curbuf->b_p_bin && curbuf->b_p_fixeol) @@ -1236,6 +1237,7 @@ static void read_input(StringBuilder *buf) break; } lp = ml_get(lnum); + lplen = (size_t)ml_get_len(lnum); written = 0; } else if (len > 0) { written += len; |