]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0310: unnecessary work in vim_strchr() and find_term_bykeys() v9.2.0310
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Mon, 6 Apr 2026 13:12:39 +0000 (13:12 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 6 Apr 2026 13:12:39 +0000 (13:12 +0000)
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 <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/strings.c
src/term.c
src/version.c

index b47422c1146f78c86d00a06c4bc3e5bfd75a3de1..8727b86060f005ec5f2c119d7f246f0c8ce5427e 100644 (file)
@@ -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)
index da63f8a8453cdd28d49e93224a2c3de2c45ec5db..468a7eb488d9c54c25e4a367268d0a71fdf0f4f0 100644 (file)
@@ -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)
index 628ebadacc1bcc2a698876c836aefb6e9b171a79..ed4cf0ecfd6aeef05bd18da618051501dd9ed061 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    310,
 /**/
     309,
 /**/