aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/linematch.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-02-05 07:06:33 +0800
committerGitHub <noreply@github.com>2025-02-05 07:06:33 +0800
commit1deb580977f4144ff3e4704765d13684e84405c5 (patch)
treecab8cc404eb779d5346c3251a30adf5d56390085 /src/nvim/linematch.c
parent4317d366691b057ffba4504c1167128a66e4e5c8 (diff)
downloadrneovim-1deb580977f4144ff3e4704765d13684e84405c5.tar.gz
rneovim-1deb580977f4144ff3e4704765d13684e84405c5.tar.bz2
rneovim-1deb580977f4144ff3e4704765d13684e84405c5.zip
vim-patch:9.1.1076: vim_strnchr() is strange and unnecessary (#32327)
Problem: vim_strnchr() is strange and unnecessary (after v9.1.1009) Solution: Remove vim_strnchr() and use memchr() instead. Also remove a comment referencing an #if that is no longer present. vim_strnchr() is strange in several ways: - It's named like vim_strchr(), but unlike vim_strchr() it doesn't support finding a multibyte char. - Its logic is similar to vim_strbyte(), but unlike vim_strbyte() it uses char instead of char_u. - It takes a pointer as its size argument, which isn't convenient for all its callers. - It allows embedded NULs, unlike other "strn*" functions which stop when encountering a NUL byte. In comparison, memchr() also allows embedded NULs, and it converts bytes in the string to (unsigned char). closes: vim/vim#16579 https://github.com/vim/vim/commit/34e1e8de91ff4a8922d454e3147ea425784aa0a0
Diffstat (limited to 'src/nvim/linematch.c')
-rw-r--r--src/nvim/linematch.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c
index 2627489106..79f4c0d692 100644
--- a/src/nvim/linematch.c
+++ b/src/nvim/linematch.c
@@ -32,12 +32,8 @@ struct diffcmppath_S {
static size_t line_len(const mmfile_t *m)
{
char *s = m->ptr;
- size_t n = (size_t)m->size;
- char *end = strnchr(s, &n, '\n');
- if (end) {
- return (size_t)(end - s);
- }
- return (size_t)m->size;
+ char *end = memchr(s, '\n', (size_t)m->size);
+ return end ? (size_t)(end - s) : (size_t)m->size;
}
#define MATCH_CHAR_MAX_LEN 800
@@ -148,9 +144,9 @@ static int count_n_matched_chars(mmfile_t **sp, const size_t n, bool iwhite)
mmfile_t fastforward_buf_to_lnum(mmfile_t s, linenr_T lnum)
{
for (int i = 0; i < lnum - 1; i++) {
- size_t n = (size_t)s.size;
- s.ptr = strnchr(s.ptr, &n, '\n');
- s.size = (int)n;
+ char *line_end = memchr(s.ptr, '\n', (size_t)s.size);
+ s.size = line_end ? (int)(s.size - (line_end - s.ptr)) : 0;
+ s.ptr = line_end;
if (!s.ptr) {
break;
}