Mercurial > vim
changeset 32266:769df9d385e0 v9.0.1464
patch 9.0.1464: strace filetype detection is expensive
Commit: https://github.com/vim/vim/commit/6e5a9f948221b52caaaf106079cb3430c4dd7c77
Author: Federico Mengozzi <19249682+fedemengo@users.noreply.github.com>
Date: Mon Apr 17 22:31:38 2023 +0100
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 17 Apr 2023 23:45:03 +0200 |
parents | ca3f9e8b3c03 |
children | e52c696a56f3 |
files | runtime/autoload/dist/script.vim src/testdir/test_filetype.vim src/version.c |
diffstat | 3 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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