Skip to content

Commit 6e5a9f9

Browse files
fedemengobrammool
authored andcommitted
patch 9.0.1464: strace filetype detection is expensive
Problem: Strace filetype detection is expensive. Solution: Match with a cheap pattern first. (Federico Mengozzi, closes #12220)
1 parent 4c42c7e commit 6e5a9f9

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

runtime/autoload/dist/script.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ def DetectFromText(line1: string)
338338
set ft=virata
339339

340340
# Strace
341-
elseif line1 =~ '[0-9:.]* *execve(' || line1 =~ '^__libc_start_main'
341+
# inaccurate fast match first, then use accurate slow match
342+
elseif (line1 =~ 'execve(' && line1 =~ '^[0-9:.]* *execve(')
343+
|| line1 =~ '^__libc_start_main'
342344
set ft=strace
343345

344346
# VSE JCL

src/testdir/test_filetype.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ func Test_filetype_detection()
733733
filetype off
734734
endfunc
735735

736+
" Content lines that should not result in filetype detection
737+
let s:false_positive_checks = {
738+
\ '': [['test execve("/usr/bin/pstree", ["pstree"], 0x7ff0 /* 63 vars */) = 0']],
739+
\ }
740+
736741
" Filetypes detected from the file contents by scripts.vim
737742
let s:script_checks = {
738743
\ 'virata': [['% Virata'],
@@ -824,6 +829,7 @@ func Run_script_detection(test_dict)
824829
endfunc
825830

826831
func Test_script_detection()
832+
call Run_script_detection(s:false_positive_checks)
827833
call Run_script_detection(s:script_checks)
828834
call Run_script_detection(s:script_env_checks)
829835
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1464,
698700
/**/
699701
1463,
700702
/**/

0 commit comments

Comments
 (0)