vim-patch:9.2.0754: repeated completion length lookup in search_for_exact_line (#40511)

Problem:  search_for_exact_line() repeatedly calls ins_compl_len() and
          relies on ternary operator precedence.
Solution: Cache the completion length and parenthesize the ternary
          expression.

closes: vim/vim#20678

ac443b9924

Co-authored-by: glepnir <glephunter@gmail.com>
(cherry picked from commit 3fea2a7fc5)
This commit is contained in:
zeertzjq
2026-07-01 07:08:58 +08:00
committed by github-actions[bot]
parent 71343dad79
commit e41b309abe

View File

@@ -1470,6 +1470,7 @@ end_do_search:
int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat) int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat)
{ {
linenr_T start = 0; linenr_T start = 0;
int compl_len = ins_compl_len();
if (buf->b_ml.ml_line_count == 0) { if (buf->b_ml.ml_line_count == 0) {
return FAIL; return FAIL;
@@ -1515,9 +1516,9 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char *pat)
} }
} else if (*p != NUL) { // Ignore empty lines. } else if (*p != NUL) { // Ignore empty lines.
// Expanding lines or words. // Expanding lines or words.
assert(ins_compl_len() >= 0); assert(compl_len >= 0);
if ((p_ic ? mb_strnicmp(p, pat, (size_t)ins_compl_len()) if ((p_ic ? mb_strnicmp(p, pat, (size_t)compl_len)
: strncmp(p, pat, (size_t)ins_compl_len())) == 0) { : strncmp(p, pat, (size_t)compl_len)) == 0) {
return OK; return OK;
} }
} }
@@ -2588,9 +2589,8 @@ static int is_zero_width(char *pattern, size_t patternlen, bool move, pos_T *cur
break; break;
} }
} while (regmatch.regprog != NULL } while (regmatch.regprog != NULL
&& direction == FORWARD && (direction == FORWARD ? regmatch.startpos[0].col < pos.col
? regmatch.startpos[0].col < pos.col : regmatch.startpos[0].col > pos.col));
: regmatch.startpos[0].col > pos.col);
if (called_emsg == called_emsg_before) { if (called_emsg == called_emsg_before) {
result = (nmatched != 0 result = (nmatched != 0