diff options
author | Federico Mengozzi <19249682+fedemengo@users.noreply.github.com> | 2023-04-17 22:31:38 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2023-04-17 22:31:38 +0100 |
commit | 6e5a9f948221b52caaaf106079cb3430c4dd7c77 (patch) | |
tree | e22fbc7d41e12e87de97afdaff9dc24f34f04ad5 | |
parent | 4c42c7eef43ff0f58fa574f7a900c8a3313f372e (diff) | |
download | vim-git-6e5a9f948221b52caaaf106079cb3430c4dd7c77.tar.gz |
patch 9.0.1464: strace filetype detection is expensivev9.0.1464
Problem: Strace filetype detection is expensive.
Solution: Match with a cheap pattern first. (Federico Mengozzi,
closes #12220)
-rw-r--r-- | runtime/autoload/dist/script.vim | 4 | ||||
-rw-r--r-- | src/testdir/test_filetype.vim | 6 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 11 insertions, 1 deletions
diff --git a/runtime/autoload/dist/script.vim b/runtime/autoload/dist/script.vim index f86c42898..e95c633fc 100644 --- a/runtime/autoload/dist/script.vim +++ b/runtime/autoload/dist/script.vim @@ -338,7 +338,9 @@ def DetectFromText(line1: string) set ft=virata # Strace - elseif line1 =~ '[0-9:.]* *execve(' || line1 =~ '^__libc_start_main' + # inaccurate fast match first, then use accurate slow match + elseif (line1 =~ 'execve(' && line1 =~ '^[0-9:.]* *execve(') + || line1 =~ '^__libc_start_main' set ft=strace # VSE JCL diff --git a/src/testdir/test_filetype.vim b/src/testdir/test_filetype.vim index 0b8b52c88..60e4f3088 100644 --- a/src/testdir/test_filetype.vim +++ b/src/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 diff --git a/src/version.c b/src/version.c index 6c8d76e38..c050afec4 100644 --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1464, +/**/ 1463, /**/ 1462, |