From f659699a26999cba4947f3c335c6e48d05c95310 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 8 Oct 2024 08:43:44 +0800 Subject: vim-patch:9.1.0766: too many strlen() calls in ex_getln.c (#30715) Problem: too many strlen() calls in ex_getln.c Solution: refactor the code to reduce the number of strlen() calls (John Marriott) closes: vim/vim#15809 https://github.com/vim/vim/commit/ccf8907570e14396e265b742e51f5089fdf97bf5 Co-authored-by: John Marriott --- src/nvim/search.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index ff6e135df1..2a935f6878 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -380,6 +380,11 @@ char *last_search_pattern(void) return spats[RE_SEARCH].pat; } +size_t last_search_pattern_len(void) +{ + return spats[RE_SEARCH].patlen; +} + /// Return true when case should be ignored for search pattern "pat". /// Uses the 'ignorecase' and 'smartcase' options. int ignorecase(char *pat) -- cgit From 23290e7676e6f0a5cb5d9dc9fa1933df815aed33 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 29 Sep 2024 10:05:27 +0200 Subject: feat(editor): handle new multibyte sequences in normal mode replacement while the implementation is not tied to screen chars, it is a reasonable expectation to support the same size. If nvim is able to display a multibyte character, it will accept the same character as input, including in normal mode commands like r{char} --- src/nvim/search.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 2a935f6878..5d3d3db3fe 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -113,7 +113,7 @@ static int last_idx = 0; // index in spats[] for RE_LAST static uint8_t lastc[2] = { NUL, NUL }; // last character searched for static Direction lastcdir = FORWARD; // last direction of character search static bool last_t_cmd = true; // last search t_cmd -static char lastc_bytes[MB_MAXBYTES + 1]; +static char lastc_bytes[MAX_SCHAR_SIZE + 1]; static int lastc_bytelen = 1; // >1 for multi-byte char // copy of spats[], for keeping the search patterns while executing autocmds @@ -1550,14 +1550,11 @@ int searchc(cmdarg_T *cap, bool t_cmd) *lastc = (uint8_t)c; set_csearch_direction(dir); set_csearch_until(t_cmd); - lastc_bytelen = utf_char2bytes(c, lastc_bytes); - if (cap->ncharC1 != 0) { - lastc_bytelen += utf_char2bytes(cap->ncharC1, - lastc_bytes + lastc_bytelen); - if (cap->ncharC2 != 0) { - lastc_bytelen += utf_char2bytes(cap->ncharC2, - lastc_bytes + lastc_bytelen); - } + if (cap->nchar_len) { + lastc_bytelen = cap->nchar_len; + memcpy(lastc_bytes, cap->nchar_composing, (size_t)cap->nchar_len); + } else { + lastc_bytelen = utf_char2bytes(c, lastc_bytes); } } } else { // repeat previous search -- cgit From 5cfa7a72f8c40cdcc0fa93693689915e913806f1 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 20 Feb 2024 17:25:57 +0100 Subject: refactor(message): propagate highlight id instead of attrs Problem: Highlight group id is not propagated to the end of the message call stack, where ext_messages are emitted. Solution: Refactor message functions to pass along highlight group id instead of attr id. --- src/nvim/search.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index 5d3d3db3fe..bfa90ba24a 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1304,7 +1304,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char *pat, size_t patlen memset(msgbuf + pat_len, ' ', (size_t)(r - msgbuf)); } } - msg_outtrans(msgbuf, 0); + msg_outtrans(msgbuf, 0, false); msg_clr_eos(); msg_check(); @@ -3731,7 +3731,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool && action == ACTION_SHOW_ALL && files[i].matched) { msg_putchar('\n'); // cursor below last one if (!got_int) { // don't display if 'q' typed at "--more--" message - msg_home_replace_hl(new_fname); + msg_home_replace(new_fname); msg_puts(_(" (includes previously listed match)")); prev_fname = NULL; } @@ -3772,7 +3772,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool if (new_fname != NULL) { // using "new_fname" is more reliable, e.g., when // 'includeexpr' is set. - msg_outtrans(new_fname, HL_ATTR(HLF_D)); + msg_outtrans(new_fname, HLF_D + 1, false); } else { // Isolate the file name. // Include the surrounding "" or <> if present. @@ -3806,7 +3806,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool } char save_char = p[i]; p[i] = NUL; - msg_outtrans(p, HL_ATTR(HLF_D)); + msg_outtrans(p, HLF_D + 1, false); p[i] = save_char; } @@ -3858,7 +3858,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool vim_snprintf(IObuff, IOSIZE, _("Scanning included file: %s"), new_fname); - msg_trunc(IObuff, true, HL_ATTR(HLF_R)); + msg_trunc(IObuff, true, HLF_R + 1); } else if (p_verbose >= 5) { verbose_enter(); smsg(0, _("Searching included file %s"), new_fname); @@ -4032,7 +4032,7 @@ search_line: } if (!got_int) { // don't display if 'q' typed // at "--more--" message - msg_home_replace_hl(curr_fname); + msg_home_replace(curr_fname); } prev_fname = curr_fname; } @@ -4233,7 +4233,7 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI msg_puts(IObuff); snprintf(IObuff, IOSIZE, "%4" PRIdLINENR, *lnum); // Show line nr. // Highlight line numbers. - msg_puts_attr(IObuff, HL_ATTR(HLF_N)); + msg_puts_hl(IObuff, HLF_N + 1, false); msg_puts(" "); } msg_prt_line(line, false); -- cgit From ff7518b83cb270f8fcaded19bf640cf4bdfb0ff0 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 11 Nov 2024 13:06:37 +0100 Subject: refactor(highlight): make enum of builtin highlights start with 1 This makes it possible to use HLF_ values directly as highlight id:s and avoids +1 adjustments especially around messages. --- src/nvim/search.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/search.c') diff --git a/src/nvim/search.c b/src/nvim/search.c index bfa90ba24a..debc5697d1 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -3772,7 +3772,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool if (new_fname != NULL) { // using "new_fname" is more reliable, e.g., when // 'includeexpr' is set. - msg_outtrans(new_fname, HLF_D + 1, false); + msg_outtrans(new_fname, HLF_D, false); } else { // Isolate the file name. // Include the surrounding "" or <> if present. @@ -3806,7 +3806,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool } char save_char = p[i]; p[i] = NUL; - msg_outtrans(p, HLF_D + 1, false); + msg_outtrans(p, HLF_D, false); p[i] = save_char; } @@ -3858,7 +3858,7 @@ void find_pattern_in_path(char *ptr, Direction dir, size_t len, bool whole, bool vim_snprintf(IObuff, IOSIZE, _("Scanning included file: %s"), new_fname); - msg_trunc(IObuff, true, HLF_R + 1); + msg_trunc(IObuff, true, HLF_R); } else if (p_verbose >= 5) { verbose_enter(); smsg(0, _("Searching included file %s"), new_fname); @@ -4233,7 +4233,7 @@ static void show_pat_in_path(char *line, int type, bool did_show, int action, FI msg_puts(IObuff); snprintf(IObuff, IOSIZE, "%4" PRIdLINENR, *lnum); // Show line nr. // Highlight line numbers. - msg_puts_hl(IObuff, HLF_N + 1, false); + msg_puts_hl(IObuff, HLF_N, false); msg_puts(" "); } msg_prt_line(line, false); -- cgit