From 1037e26f3120e6a6a2c0c33b14a84336dee2a78f Mon Sep 17 00:00:00 2001 From: MTDL9 <40929090+MTDL9@users.noreply.github.com> Date: Sun, 30 Aug 2020 09:10:11 +0200 Subject: [PATCH] Optimize Syslog date rule using keywords in place of combinations The previous rule used combinations of Day and Month three letter terms, and was taking up about 30% of the syntax processing time. The new methods using keywords has the side effect of highlighting the three letter identifies in the whole file (they should be reasonably rare outside of dates, however) but is much faster --- syntax/log.vim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/syntax/log.vim b/syntax/log.vim index 4092a4a..a12f0e8 100644 --- a/syntax/log.vim +++ b/syntax/log.vim @@ -43,8 +43,9 @@ syn region logString start=/'\(s \|t \| \w\)\@!/ end=/'/ end=/$/ end=/s / s syn match logDate '\d\{2,4}[-\/]\(\d\{2}\|Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\)[-\/]\d\{2,4}T\?' " Matches 8 digit numbers at start of line starting with 20 syn match logDate '^20\d\{6}' -" Matches Fri Jan 09 or Feb 11 or Apr 3 -syn match logDate '\(\(Mon\|Tue\|Wed\|Thu\|Fri\|Sat\|Sun\) \)\?\(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec\) [0-9 ]\d' +" Matches Fri Jan 09 or Feb 11 or Apr 3 or Sun 3 +syn keyword logDate Mon Tue Wed Thu Fri Sat Sun Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec nextgroup=logDateDay +syn match logDateDay '\s\{1,2}\d\{1,2}' contained " Matches 12:09:38 or 00:03:38.129Z or 01:32:12.102938 +0700 syn match logTime '\d\{2}:\d\{2}:\d\{2}\(\.\d\{2,6}\)\?\(\s\?[-+]\d\{2,4}\|Z\)\?\>' nextgroup=logTimeZone,logSysColumns skipwhite @@ -112,6 +113,7 @@ hi def link logNull Constant hi def link logString String hi def link logDate Identifier +hi def link logDateDay Identifier hi def link logTime Function hi def link logTimeZone Identifier