Commit: patch 9.1.0694: matchparen is slow on a long line

9 views
Skip to first unread message

Christian Brabandt

unread,
Aug 24, 2024, 10:45:12 AM8/24/24
to vim...@googlegroups.com
patch 9.1.0694: matchparen is slow on a long line

Commit: https://github.com/vim/vim/commit/81e7513c86459c40676bd983f73c2722096d67a9
Author: zeertzjq <zeer...@outlook.com>
Date: Sat Aug 24 16:32:24 2024 +0200

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 <zeer...@outlook.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/plugin/matchparen.vim b/runtime/plugin/matchparen.vim
index 6c061c9fb..2899612dc 100644
--- a/runtime/plugin/matchparen.vim
+++ b/runtime/plugin/matchparen.vim
@@ -60,12 +60,8 @@ func s:Highlight_Matching_Pair()
let before = 0

let text = getline(c_lnum)
- let matches = matchlist(text, '\(.\)\=\%'.c_col.'c\(.\=\)')
- if empty(matches)
- let [c_before, c] = ['', '']
- else
- let [c_before, c] = matches[1:2]
- endif
+ let c_before = text->strpart(0, c_col - 1)->slice(-1)
+ let c = text->strpart(c_col - 1)->slice(0, 1)
let plist = split(&matchpairs, '.\zs[:,]')
let i = index(plist, c)
if i < 0
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_1.dump b/src/testdir/dumps/Test_matchparen_mbyte_1.dump
new file mode 100644
index 000000000..f5df150ae
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_1.dump
@@ -0,0 +1,10 @@
+>a+0&#ffffff0@7|(*&| +&@64
+|b@3|)*&|c+&@1| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_2.dump b/src/testdir/dumps/Test_matchparen_mbyte_2.dump
new file mode 100644
index 000000000..0e4e6e86a
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_2.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7>(*0&#40ffff15| +0&#ffffff0@64
+|b@3|)*0&#40ffff15|c+0&#ffffff0@1| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|1|,|9| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_3.dump b/src/testdir/dumps/Test_matchparen_mbyte_3.dump
new file mode 100644
index 000000000..85c462a5f
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_3.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*&| +&@64
+|b@3|)*&|c+&>c| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|2|,|9|-|8| @8|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_4.dump b/src/testdir/dumps/Test_matchparen_mbyte_4.dump
new file mode 100644
index 000000000..45f5d08c6
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_4.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*0&#40ffff15| +0&#ffffff0@64
+|b@3>)*0&#40ffff15|c+0&#ffffff0@1| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|2|,|5| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_5.dump b/src/testdir/dumps/Test_matchparen_mbyte_5.dump
new file mode 100644
index 000000000..45c3bfab6
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_5.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*&| +&@64
+>b@3|)*&|c+&@1| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+| +0#0000000&@56|2|,|1| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_6.dump b/src/testdir/dumps/Test_matchparen_mbyte_6.dump
new file mode 100644
index 000000000..8064a98f0
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_6.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*0&#40ffff15> +0&#ffffff0@64
+|b@3|)*0&#40ffff15|c+0&#ffffff0@1| @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|1|2|-|1@1| @6|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_7.dump b/src/testdir/dumps/Test_matchparen_mbyte_7.dump
new file mode 100644
index 000000000..4d8c64787
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_7.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*&| +&@64
+|b@3|)*&|c+&@1> @66
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|2|,|1|0|-|9| @7|A|l@1|
diff --git a/src/testdir/dumps/Test_matchparen_mbyte_8.dump b/src/testdir/dumps/Test_matchparen_mbyte_8.dump
new file mode 100644
index 000000000..c3699fd55
--- /dev/null
+++ b/src/testdir/dumps/Test_matchparen_mbyte_8.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@7|(*0&#40ffff15| +0&#ffffff0@64
+|b@3|)*0&#40ffff15> +0&#ffffff0@68
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|2|,|8|-|7| @8|A|l@1|
diff --git a/src/testdir/test_matchparen.vim b/src/testdir/test_matchparen.vim
index 70aa38ffd..49d35108a 100644
--- a/src/testdir/test_matchparen.vim
+++ b/src/testdir/test_matchparen.vim
@@ -108,5 +108,35 @@ func Test_matchparen_pum_clear()
call StopVimInTerminal(buf)
endfunc

+" Test that matchparen works with multibyte chars in 'matchpairs'
+func Test_matchparen_mbyte()
+ CheckScreendump
+
+ let lines =<< trim END
+ source $VIMRUNTIME/plugin/matchparen.vim
+ call setline(1, ['aaaaaaaa(', 'bbbb)cc'])
+ set matchpairs+=(:)
+ END
+
+ call writefile(lines, 'XmatchparenMbyte', 'D')
+ let buf = RunVimInTerminal('-S XmatchparenMbyte', #{rows: 10})
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_1', {})
+ call term_sendkeys(buf, "$")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_2', {})
+ call term_sendkeys(buf, "j")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_3', {})
+ call term_sendkeys(buf, "2h")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_4', {})
+ call term_sendkeys(buf, "0")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_5', {})
+ call term_sendkeys(buf, "kA")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_6', {})
+ call term_sendkeys(buf, "\<Down>")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_7', {})
+ call term_sendkeys(buf, "\<C-W>")
+ call VerifyScreenDump(buf, 'Test_matchparen_mbyte_8', {})
+
+ call StopVimInTerminal(buf)
+endfunc

" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 9522cc809..f28c66f59 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 694,
/**/
693,
/**/
Reply all
Reply to author
Forward
0 new messages