]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1464: strace filetype detection is expensive v9.0.1464
authorFederico Mengozzi <19249682+fedemengo@users.noreply.github.com>
Mon, 17 Apr 2023 21:31:38 +0000 (22:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 17 Apr 2023 21:31:38 +0000 (22:31 +0100)
Problem:    Strace filetype detection is expensive.
Solution:   Match with a cheap pattern first. (Federico Mengozzi,
            closes #12220)

runtime/autoload/dist/script.vim
src/testdir/test_filetype.vim
src/version.c

index f86c42898be64d0f61a78fd49cff6e03b8e60f84..e95c633fcf97cdb4d4239b1482439e056a16f9c3 100644 (file)
@@ -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
index 0b8b52c88ec13fa76d622b57efde082a1eafff1a..60e4f30880e9a00edef094aa1b88de94eb68b163 100644 (file)
@@ -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
index 6c8d76e38afb5ebfe68002405516df3483cb20f1..c050afec4abc73c8367ad4594a6e75a1d8c98446 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1464,
 /**/
     1463,
 /**/