From f5b242e57b4263c9a5fcfa0ad4e9d416db552ce1 Mon Sep 17 00:00:00 2001 From: nfnty Date: Tue, 21 Feb 2017 17:24:11 +0100 Subject: [PATCH] syntax: Combine regexes Improves performance --- syntax/python.vim | 58 ++++++++++++----------------------------------- tests/test.py | 2 +- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 6208ab8..282e58a 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -367,28 +367,19 @@ endif " if s:Enabled('g:python_highlight_builtin_funcs') + let s:funcs_re = '__import__|abs|all|any|bin|chr|classmethod|cmp|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip' + if s:Python2Syntax() - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters + let s:funcs_re .= '|apply|basestring|buffer|callable|coerce|execfile|file|help|intern|long|raw_input|reduce|reload|unichr|unicode|xrange' if s:Enabled('g:python_print_as_function') - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters + let s:funcs_re .= '|print' endif else - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters + let s:funcs_re .= '|ascii|exec|memoryview|print' endif - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters - syn match pythonBuiltinFunc '\v\.@\ze\(' nextgroup=FunctionParameters + + execute 'syn match pythonBuiltinFunc ''\v\.@\ze\('' nextgroup=FunctionParameters' + unlet s:funcs_re endif " @@ -396,37 +387,16 @@ endif " if s:Enabled('g:python_highlight_exceptions') + let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDepricationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' + if s:Python2Syntax() - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters + let s:exs_re .= '|StandardError' else - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters + let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|ResourceWarning' endif - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters - syn match pythonExClass '\v\.@' nextgroup=FunctionParameters + execute 'syn match pythonExClass ''\v\.@'' nextgroup=FunctionParameters' + unlet s:exs_re endif if s:Enabled('g:python_slow_sync') diff --git a/tests/test.py b/tests/test.py index 65fa4c3..03ce8b6 100644 --- a/tests/test.py +++ b/tests/test.py @@ -40,7 +40,7 @@ async def Test __import__() abs() all() any() apply() basestring() buffer() callable() chr() classmethod() cmp() coerce() compile() complex() delattr() dir() divmod() enumerate() eval() execfile() file() filter() getattr() globals() hasattr() hash() help() hex() id() input() intern() isinstance() -issubclass() iter() len() locals() long() map() max() min() oct() open() ord() pow() property() +issubclass() iter() len() locals() long() map() max() min() oct() open() ord() pow() print() property() range() raw_input() reduce() reload() repr() reversed() round() setattr() slice() sorted() staticmethod() sum() super() type() unichr() unicode() vars() xrange() zip()