From: Yasuhiro Matsumoto Date: Mon, 6 Apr 2026 13:12:39 +0000 (+0000) Subject: patch 9.2.0310: unnecessary work in vim_strchr() and find_term_bykeys() X-Git-Tag: v9.2.0310^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9981bbc8e4b5736d8f5cd444577cf2db8c029a5;p=thirdparty%2Fvim.git patch 9.2.0310: unnecessary work in vim_strchr() and find_term_bykeys() problem: unnecessary work in vim_strchr() and find_term_bykeys() Solution: Redirect vim_strchr() to vim_strbyte() for ASCII input Add an early exit to find_term_bykeys() using the terminal leader table, mirroring check_termcode(). Reduces instruction count on startup by about 27%. (Yasuhiro Matsumoto) closes: #19902 Signed-off-by: Yasuhiro Matsumoto Signed-off-by: Christian Brabandt --- diff --git a/src/strings.c b/src/strings.c index b47422c114..8727b86060 100644 --- a/src/strings.c +++ b/src/strings.c @@ -626,6 +626,8 @@ vim_strchr(char_u *string, int c) int b; p = string; + if (enc_utf8 && c > 0 && c < 0x80) + return vim_strbyte(string, c); if (enc_utf8 && c >= 0x80) { while (*p != NUL) diff --git a/src/term.c b/src/term.c index da63f8a845..468a7eb488 100644 --- a/src/term.c +++ b/src/term.c @@ -7209,6 +7209,13 @@ find_term_bykeys(char_u *src, int *matchlen) int slen, modslen; int thislen; + // Most input bytes cannot start a terminal code. Reuse the same leader + // table as check_termcode() to avoid scanning termcodes[] unnecessarily. + if (need_gather) + gather_termleader(); + if (*src == NUL || vim_strchr(termleader, *src) == NULL) + return -1; + // find longest match // borrows part of check_termcode for (i = 0; i < tc_len; ++i) diff --git a/src/version.c b/src/version.c index 628ebadacc..ed4cf0ecfd 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 310, /**/ 309, /**/