patch 9.2.0310: unnecessary work in vim_strchr() and find_term_bykeys()

Commit: 
https://github.com/vim/vim/commit/f9981bbc8e4b5736d8f5cd444577cf2db8c029a5
Author: Yasuhiro Matsumoto <[email protected]>
Date:   Mon Apr 6 13:12:39 2026 +0000

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/strings.c b/src/strings.c
index b47422c11..8727b8606 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 da63f8a84..468a7eb48 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 628ebadac..ed4cf0ecf 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,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1w9jnF-006rqw-S5%40256bit.org.

Raspunde prin e-mail lui