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)

6e5a9f9482

Co-authored-by: Federico Mengozzi <19249682+fedemengo@users.noreply.github.com>
This commit is contained in:
Christian Clason 2023-04-19 09:41:26 +02:00 committed by GitHub
parent 95c6e1b741
commit 6d9f5b6bf0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -1550,8 +1550,15 @@ local patterns_text = {
['^SNNS pattern definition file'] = 'snnspat', ['^SNNS pattern definition file'] = 'snnspat',
['^SNNS result file'] = 'snnsres', ['^SNNS result file'] = 'snnsres',
['^%%.-[Vv]irata'] = { 'virata', { start_lnum = 1, end_lnum = 5 } }, ['^%%.-[Vv]irata'] = { 'virata', { start_lnum = 1, end_lnum = 5 } },
['[0-9:%.]* *execve%('] = 'strace', function(lines)
['^__libc_start_main'] = 'strace', 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 -- VSE JCL
['^\\* $$ JOB\\>'] = { 'vsejcl', { vim_regex = true } }, ['^\\* $$ JOB\\>'] = { 'vsejcl', { vim_regex = true } },
['^// *JOB\\>'] = { 'vsejcl', { vim_regex = true } }, ['^// *JOB\\>'] = { 'vsejcl', { vim_regex = true } },

View File

@ -733,6 +733,11 @@ func Test_filetype_detection()
filetype off filetype off
endfunc 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 " Filetypes detected from the file contents by scripts.vim
let s:script_checks = { let s:script_checks = {
\ 'virata': [['% Virata'], \ 'virata': [['% Virata'],
@ -824,6 +829,7 @@ func Run_script_detection(test_dict)
endfunc endfunc
func Test_script_detection() 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_checks)
call Run_script_detection(s:script_env_checks) call Run_script_detection(s:script_env_checks)
endfunc endfunc