highlighter: Cache syntax highlighting attributes

Should in theory improve performance by quiet a lot.
This commit is contained in:
Christian Brabandt 2017-08-11 11:26:35 +02:00
parent e9a7a12d9e
commit a96681d459
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
2 changed files with 22 additions and 7 deletions

View File

@ -10,6 +10,7 @@ let s:is_win32term = (has('win32') || has('win64')) &&
let s:separators = {}
let s:accents = {}
let s:hl_groups = {}
function! s:gui2cui(rgb, fallback)
if a:rgb == ''
@ -47,14 +48,24 @@ function! s:get_array(fg, bg, opts)
\ : [ '', '', a:fg, a:bg, opts ]
endfunction
function! airline#highlighter#reset_hlcache()
let s:hl_groups = {}
endfunction
function! airline#highlighter#get_highlight(group, ...)
if has_key(s:hl_groups, a:group)
return s:hl_groups[a:group]
else
let fg = s:get_syn(a:group, 'fg')
let bg = s:get_syn(a:group, 'bg')
let reverse = g:airline_gui_mode ==# 'gui'
\ ? synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'gui')
\ : synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'cterm')
\|| synIDattr(synIDtrans(hlID(a:group)), 'reverse', 'term')
return reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
let res = reverse ? s:get_array(bg, fg, a:000) : s:get_array(fg, bg, a:000)
endif
let s:hl_groups[a:group] = res
return res
endfunction
function! airline#highlighter#get_highlight2(fg, bg, ...)
@ -98,6 +109,9 @@ function! airline#highlighter#exec(group, colors)
\ s:Get(colors, 4, 'gui='), s:Get(colors, 4, 'cterm='),
\ s:Get(colors, 4, 'term='))
exe cmd
if has_key(s:hl_groups, a:group)
let s:hl_groups[a:group] = colors
endif
endif
endfunction

View File

@ -57,6 +57,7 @@ endfunction
function! s:on_colorscheme_changed()
call s:init()
unlet! g:airline#highlighter#normal_fg_hi
call airline#highlighter#reset_hlcache()
let g:airline_gui_mode = airline#init#gui_mode()
if !s:theme_in_vimrc
call airline#switch_matching_theme()