Skip to content

Commit 96d5db4

Browse files
committed
Optimize some keyword style syntax patterns
Using the 'old' engine is at least twice as fast and up to an order of magnitude faster for these types of literal alternation patterns. These syntax groups should mostly be using syn-keyword but we need to lower the priority so later syn-match groups can override them as needed.
1 parent d04ba6d commit 96d5db4

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

syntax/ruby.vim

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ syn cluster rubyDeclaration contains=rubyAliasDeclaration,rubyAliasDeclaration2,
342342

343343
" Keywords {{{1
344344
" TODO: reorganise
345-
syn match rubyControl "\<\%(break\|in\|next\|redo\|retry\|return\)\>"
346-
syn match rubyKeyword "\<\%(super\|yield\)\>"
347-
syn match rubyBoolean "\<\%(true\|false\)\>[?!]\@!"
348-
syn match rubyPseudoVariable "\<\(self\|nil\)\>[?!]\@!"
349-
syn match rubyPseudoVariable "\<__\%(ENCODING\|dir\|FILE\|LINE\|callee\|method\)__\>"
350-
syn match rubyBeginEnd "\<\%(BEGIN\|END\)\>"
345+
syn match rubyControl "\%#=1\<\%(break\|in\|next\|redo\|retry\|return\)\>"
346+
syn match rubyKeyword "\%#=1\<\%(super\|yield\)\>"
347+
syn match rubyBoolean "\%#=1\<\%(true\|false\)\>[?!]\@!"
348+
syn match rubyPseudoVariable "\%#=1\<\(self\|nil\)\>[?!]\@!"
349+
syn match rubyPseudoVariable "\%#=1\<__\%(ENCODING\|dir\|FILE\|LINE\|callee\|method\)__\>"
350+
syn match rubyBeginEnd "\%#=1\<\%(BEGIN\|END\)\>"
351351

352352
" Expensive Mode {{{1
353353
" Match 'end' with the appropriate opening keyword for syntax based folding
@@ -410,19 +410,20 @@ endif
410410

411411
" Special Methods {{{1
412412
if !exists("ruby_no_special_methods")
413-
syn match rubyAccess "\<\%(public\|protected\|private\)\>"
414-
syn match rubyAccess "\<\%(public_class_method\|private_class_method\)\>"
415-
syn match rubyAccess "\<\%(public_constant\|private_constant\)\>"
416-
syn match rubyAccess "\<module_function\>"
417-
syn match rubyAttribute "\%(\%(^\|;\)\s*\)\@<=attr\>\(\s*[.=]\)\@!" " attr is a common variable name
418-
syn match rubyAttribute "\<\%(attr_accessor\|attr_reader\|attr_writer\)\>"
419-
syn match rubyControl "\<\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>"
420-
syn match rubyEval "\<\%(eval\|class_eval\|instance_eval\|module_eval\)\>"
421-
syn match rubyException "\<\%(raise\|fail\|catch\|throw\)\>"
422-
syn match rubyInclude "\<\%(autoload\|gem\|load\|require\|require_relative\)\>"
423-
syn match rubyKeyword "\<\%(callcc\|caller\|lambda\|proc\)\>"
424-
syn match rubyMacro "\<\%(extend\|include\|prepend\|refine\|using\)\>"
425-
syn match rubyMacro "\<\%(alias_method\|define_method\|define_singleton_method\|remove_method\|undef_method\)\>"
413+
syn match rubyAccess "\<\%(public\|protected\|private\)\>" " use re=2
414+
syn match rubyAccess "\%#=1\<\%(public\|private\)_class_method\>"
415+
syn match rubyAccess "\%#=1\<\%(public\|private\)_constant\>"
416+
syn match rubyAccess "\%#=1\<module_function\>"
417+
syn match rubyAttribute "\%#=1\%(\%(^\|;\)\s*\)\@<=attr\>\(\s*[.=]\)\@!" " attr is a common variable name
418+
syn match rubyAttribute "\%#=1\<attr_\%(accessor\|reader\|writer\)\>"
419+
syn match rubyControl "\%#=1\<\%(abort\|at_exit\|exit\|fork\|loop\|trap\)\>"
420+
syn match rubyEval "\%#=1\<eval\>"
421+
syn match rubyEval "\%#=1\<\%(class\|instance\|module\)_eval\>"
422+
syn match rubyException "\%#=1\<\%(raise\|fail\|catch\|throw\)\>"
423+
syn match rubyInclude "\%#=1\<\%(autoload\|gem\|load\|require\%(_relative\)\=\)\>"
424+
syn match rubyKeyword "\%#=1\<\%(callcc\|caller\|lambda\|proc\)\>"
425+
syn match rubyMacro "\%#=1\<\%(extend\|include\|prepend\|refine\|using\)\>"
426+
syn match rubyMacro "\%#=1\<\%(alias\|define\|define_singleton\|remove\|undef\)_method\>"
426427
endif
427428

428429
" Comments and Documentation {{{1
@@ -455,9 +456,9 @@ syn match rubyKeywordAsMethod "\%(\%(\.\@1<!\.\)\|&\.\|::\)\_s*\%([_[:lower:]][_
455456
syn match rubyBangPredicateMethod "\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]"
456457

457458
if !exists("ruby_no_special_methods")
458-
syn match rubyControl "\<exit!" display
459+
syn match rubyControl "\%#=1\<exit!" display
459460
endif
460-
syn match rubyDefinedOperator "\<defined?" display
461+
syn match rubyDefinedOperator "\%#=1\<defined?" display
461462

462463
" 1.9-style Hash Keys and Keyword Parameters {{{1
463464
syn match rubySymbol "\%([{(|,]\_s*\)\@<=\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]\=::\@!"he=e-1

0 commit comments

Comments
 (0)