From a96681d45928fa540107854444e5d755d5f80abc Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Fri, 11 Aug 2017 11:26:35 +0200 Subject: [PATCH] highlighter: Cache syntax highlighting attributes Should in theory improve performance by quiet a lot. --- autoload/airline/highlighter.vim | 28 +++++++++++++++++++++------- plugin/airline.vim | 1 + 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 4fa3d464..f58ca2af 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -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, ...) - 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) + 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') + 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 diff --git a/plugin/airline.vim b/plugin/airline.vim index 84f2048d..51927ded 100644 --- a/plugin/airline.vim +++ b/plugin/airline.vim @@ -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()