summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/syntax/python.vim
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2026-03-12 07:55:00 +0800
committerGitHub <noreply@github.com>2026-03-12 07:55:00 +0800
commit99a0b2f7b86d447af752ee7436dd5fd69fc6a101 (patch)
tree6199374d8dabde7dfa33dcb077c6b1a96db298b8 /runtime/syntax/python.vim
parent4558fc02dee5cf99439bfed47d42fd38fd94d2b1 (diff)
vim-patch:2cf18fc: runtime(python): Update syntax, improve pythonNumber pattern performance (#38263)
- Improve the performance of all pythonNumber patterns by unrolling digit/underscore sequence loops. - Split the float literal pattern into two simpler patterns. fixes: vim/vim#19625 (Reported by James McCoy) closes: vim/vim#19630 https://github.com/vim/vim/commit/2cf18fcc240030880bbd138e5174e436a3f20823 Co-authored-by: Doug Kearns <dougkearns@gmail.com>
Diffstat (limited to 'runtime/syntax/python.vim')
-rw-r--r--runtime/syntax/python.vim22
1 files changed, 14 insertions, 8 deletions
diff --git a/runtime/syntax/python.vim b/runtime/syntax/python.vim
index 1e7bf3cd07..24c2657e15 100644
--- a/runtime/syntax/python.vim
+++ b/runtime/syntax/python.vim
@@ -5,6 +5,7 @@
" 2025 Sep 25 by Vim Project: fix wrong type highlighting #18394
" 2025 Dec 03 by Vim Project: highlight t-strings #18679
" 2026 Jan 26 by Vim Project: highlight constants #18922
+" 2026 Mar 11 by Vim Project: fix number performance #19630
" Credits: Neil Schemenauer <nas@python.ca>
" Dmitry Vasiliev
" Rob B
@@ -270,16 +271,21 @@ syn match pythonEscape "\\$"
" https://docs.python.org/reference/lexical_analysis.html#numeric-literals
if !exists("python_no_number_highlight")
" numbers (including complex)
- syn match pythonNumber "\<0[oO]\%(_\=\o\)\+\>"
- syn match pythonNumber "\<0[xX]\%(_\=\x\)\+\>"
- syn match pythonNumber "\<0[bB]\%(_\=[01]\)\+\>"
- syn match pythonNumber "\<\%([1-9]\%(_\=\d\)*\|0\+\%(_\=0\)*\)\>"
- syn match pythonNumber "\<\d\%(_\=\d\)*[jJ]\>"
- syn match pythonNumber "\<\d\%(_\=\d\)*[eE][+-]\=\d\%(_\=\d\)*[jJ]\=\>"
+ syn match pythonNumber "\<0[oO]_\=\o\+\%(_\o\+\)*\>"
+ syn match pythonNumber "\<0[xX]_\=\x\+\%(_\x\+\)*\>"
+ syn match pythonNumber "\<0[bB]_\=[01]\+\%(_[01]\+\)*\>"
+ syn match pythonNumber "\<\%([1-9]\d*\%(_\d\+\)*\|0\+\%(_0\+\)*\)\>"
+ syn match pythonNumber "\<\d\+\%(_\d\+\)*[jJ]\>"
+ syn match pythonNumber "\<\d\+\%(_\d\+\)*[eE][+-]\=\d\+\%(_\d\+\)*[jJ]\=\>"
+ " \d\.
syn match pythonNumber
- \ "\<\d\%(_\=\d\)*\.\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\%(\W\|$\)\@="
+ \ "\<\d\+\%(_\d\+\)*\.\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\%(\W\|$\)\@="
+ " \d\.\d
syn match pythonNumber
- \ "\%(^\|\W\)\@1<=\%(\d\%(_\=\d\)*\)\=\.\d\%(_\=\d\)*\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\>"
+ \ "\<\d\+\%(_\d\+\)*\.\d\+\%(_\d\+\)*\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\>"
+ " \.\d
+ syn match pythonNumber
+ \ "\%(^\|\W\)\@1<=\.\d\+\%(_\d\+\)*\%([eE][+-]\=\d\+\%(_\d\+\)*\)\=[jJ]\=\>"
endif
" Group the built-ins in the order in the 'Python Library Reference' for