Skip to content

Commit f9981bb

Browse files
mattnchrisbra
authored andcommitted
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 <mattn.jp@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4368ad3 commit f9981bb

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/strings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ vim_strchr(char_u *string, int c)
626626
int b;
627627

628628
p = string;
629+
if (enc_utf8 && c > 0 && c < 0x80)
630+
return vim_strbyte(string, c);
629631
if (enc_utf8 && c >= 0x80)
630632
{
631633
while (*p != NUL)

src/term.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7209,6 +7209,13 @@ find_term_bykeys(char_u *src, int *matchlen)
72097209
int slen, modslen;
72107210
int thislen;
72117211

7212+
// Most input bytes cannot start a terminal code. Reuse the same leader
7213+
// table as check_termcode() to avoid scanning termcodes[] unnecessarily.
7214+
if (need_gather)
7215+
gather_termleader();
7216+
if (*src == NUL || vim_strchr(termleader, *src) == NULL)
7217+
return -1;
7218+
72127219
// find longest match
72137220
// borrows part of check_termcode
72147221
for (i = 0; i < tc_len; ++i)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
310,
737739
/**/
738740
309,
739741
/**/

0 commit comments

Comments
 (0)