Skip to content

Commit 81e7513

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0694: matchparen is slow on a long line
Problem: The matchparen plugin is slow on a long line. Solution: Don't use a regexp to get char at and before cursor. (zeertzjq) Example: ```vim call setline(1, repeat(' foobar', 100000)) runtime plugin/matchparen.vim normal! $hhhhhhhh ``` closes: #15568 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent dc2c75c commit 81e7513

11 files changed

+114
-6
lines changed

runtime/plugin/matchparen.vim

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,8 @@ func s:Highlight_Matching_Pair()
6060
let before = 0
6161

6262
let text = getline(c_lnum)
63-
let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\=\)')
64-
if empty(matches)
65-
let [c_before, c] = ['', '']
66-
else
67-
let [c_before, c] = matches[1:2]
68-
endif
63+
let c_before = text->strpart(0, c_col - 1)->slice(-1)
64+
let c = text->strpart(c_col - 1)->slice(0, 1)
6965
let plist = split(&matchpairs, '.\zs[:,]')
7066
let i = index(plist, c)
7167
if i < 0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
>a+0&#ffffff0@7|(*&| +&@64
2+
|b@3|)*&|c+&@1| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
| +0#0000000&@56|1|,|1| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7>(*0&#40ffff15| +0&#ffffff0@64
2+
|b@3|)*0&#40ffff15|c+0&#ffffff0@1| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
| +0#0000000&@56|1|,|9| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*&| +&@64
2+
|b@3|)*&|c+&>c| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
| +0#0000000&@56|2|,|9|-|8| @8|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*0&#40ffff15| +0&#ffffff0@64
2+
|b@3>)*0&#40ffff15|c+0&#ffffff0@1| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
| +0#0000000&@56|2|,|5| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*&| +&@64
2+
>b@3|)*&|c+&@1| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
| +0#0000000&@56|2|,|1| @10|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*0&#40ffff15> +0&#ffffff0@64
2+
|b@3|)*0&#40ffff15|c+0&#ffffff0@1| @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|1|2|-|1@1| @6|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*&| +&@64
2+
|b@3|)*&|c+&@1> @66
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|2|,|1|0|-|9| @7|A|l@1|
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
|a+0&#ffffff0@7|(*0&#40ffff15| +0&#ffffff0@64
2+
|b@3|)*0&#40ffff15> +0&#ffffff0@68
3+
|~+0#4040ff13&| @73
4+
|~| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|2|,|8|-|7| @8|A|l@1|

src/testdir/test_matchparen.vim

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,35 @@ func Test_matchparen_pum_clear()
108108
call StopVimInTerminal(buf)
109109
endfunc
110110

111+
" Test that matchparen works with multibyte chars in 'matchpairs'
112+
func Test_matchparen_mbyte()
113+
CheckScreendump
114+
115+
let lines =<< trim END
116+
source $VIMRUNTIME/plugin/matchparen.vim
117+
call setline(1, ['aaaaaaaa(', 'bbbb)cc'])
118+
set matchpairs+=(:)
119+
END
120+
121+
call writefile(lines, 'XmatchparenMbyte', 'D')
122+
let buf = RunVimInTerminal('-S XmatchparenMbyte', #{rows: 10})
123+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_1', {})
124+
call term_sendkeys(buf, "$")
125+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_2', {})
126+
call term_sendkeys(buf, "j")
127+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_3', {})
128+
call term_sendkeys(buf, "2h")
129+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_4', {})
130+
call term_sendkeys(buf, "0")
131+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_5', {})
132+
call term_sendkeys(buf, "kA")
133+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_6', {})
134+
call term_sendkeys(buf, "\<Down>")
135+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_7', {})
136+
call term_sendkeys(buf, "\<C-W>")
137+
call VerifyScreenDump(buf, 'Test_matchparen_mbyte_8', {})
138+
139+
call StopVimInTerminal(buf)
140+
endfunc
111141

112142
" vim: shiftwidth=2 sts=2 expandtab

0 commit comments

Comments
 (0)