diff options
author | Christian Clason <c.clason@uni-graz.at> | 2023-04-19 09:41:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-19 09:41:26 +0200 |
commit | 6d9f5b6bf0fc324b33ce01f74a6030c9271b1a01 (patch) | |
tree | d942589576d670c851119f7f90ad720f07d311a1 | |
parent | 95c6e1b7418e37530352418e93a18366acef6242 (diff) | |
download | rneovim-6d9f5b6bf0fc324b33ce01f74a6030c9271b1a01.tar.gz rneovim-6d9f5b6bf0fc324b33ce01f74a6030c9271b1a01.tar.bz2 rneovim-6d9f5b6bf0fc324b33ce01f74a6030c9271b1a01.zip |
vim-patch:9.0.1464: strace filetype detection is expensive (#23175)
Problem: Strace filetype detection is expensive.
Solution: Match with a cheap pattern first. (Federico Mengozzi,
closes vim/vim#12220)
https://github.com/vim/vim/commit/6e5a9f948221b52caaaf106079cb3430c4dd7c77
Co-authored-by: Federico Mengozzi <19249682+fedemengo@users.noreply.github.com>
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 11 | ||||
-rw-r--r-- | test/old/testdir/test_filetype.vim | 6 |
2 files changed, 15 insertions, 2 deletions
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index d1eabadc4a..94114ae7c3 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -1550,8 +1550,15 @@ local patterns_text = { ['^SNNS pattern definition file'] = 'snnspat', ['^SNNS result file'] = 'snnsres', ['^%%.-[Vv]irata'] = { 'virata', { start_lnum = 1, end_lnum = 5 } }, - ['[0-9:%.]* *execve%('] = 'strace', - ['^__libc_start_main'] = 'strace', + function(lines) + if + -- inaccurate fast match first, then use accurate slow match + (lines[1]:find('execve%(') and lines[1]:find('^[0-9:%.]* *execve%(')) + or lines[1]:find('^__libc_start_main') + then + return 'strace' + end + end, -- VSE JCL ['^\\* $$ JOB\\>'] = { 'vsejcl', { vim_regex = true } }, ['^// *JOB\\>'] = { 'vsejcl', { vim_regex = true } }, diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 150cf50c2a..af0005e98c 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -733,6 +733,11 @@ func Test_filetype_detection() filetype off endfunc +" Content lines that should not result in filetype detection +let s:false_positive_checks = { + \ '': [['test execve("/usr/bin/pstree", ["pstree"], 0x7ff0 /* 63 vars */) = 0']], + \ } + " Filetypes detected from the file contents by scripts.vim let s:script_checks = { \ 'virata': [['% Virata'], @@ -824,6 +829,7 @@ func Run_script_detection(test_dict) endfunc func Test_script_detection() + call Run_script_detection(s:false_positive_checks) call Run_script_detection(s:script_checks) call Run_script_detection(s:script_env_checks) endfunc |