From 99b7cdf334c7e60498b037f45273cc02f85ab6fe Mon Sep 17 00:00:00 2001 From: Bailey Ling Date: Fri, 1 Nov 2013 00:54:10 -0400 Subject: [PATCH] improve performance with accent cache (#326). --- autoload/airline/highlighter.vim | 10 +++++++++- autoload/airline/section.vim | 1 + t/highlighter.vim | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 24aa6fa..f5e6846 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -3,6 +3,7 @@ let s:is_win32term = (has('win32') || has('win64')) && !has('gui_running') let s:separators = {} +let s:accents = {} function! s:gui2cui(rgb, fallback) if a:rgb == '' @@ -94,6 +95,10 @@ function! airline#highlighter#add_separator(from, to, inverse) call exec_separator({}, a:from, a:to, a:inverse, '') endfunction +function! airline#highlighter#add_accent(accent) + let s:accents[a:accent] = 1 +endfunction + function! airline#highlighter#highlight_modified_inactive(bufnr) if getbufvar(a:bufnr, '&modified') let colors = exists('g:airline#themes#{g:airline_theme}#palette.inactive_modified.airline_c') @@ -121,7 +126,10 @@ function! airline#highlighter#highlight(modes) let mode_colors = kvp[1] call airline#highlighter#exec(kvp[0].suffix, mode_colors) - for accent in keys(p.accents) + for accent in keys(s:accents) + if !has_key(p.accents, accent) + continue + endif let colors = copy(mode_colors) if p.accents[accent][0] != '' let colors[0] = p.accents[accent][0] diff --git a/autoload/airline/section.vim b/autoload/airline/section.vim index aba88a0..4562bac 100644 --- a/autoload/airline/section.vim +++ b/autoload/airline/section.vim @@ -6,6 +6,7 @@ let s:spc = g:airline_symbols.space function! s:wrap_accent(part, value) if exists('a:part.accent') + call airline#highlighter#add_accent(a:part.accent) return '%#__accent_'.(a:part.accent).'#'.a:value.'%#__restore__#' endif return a:value diff --git a/t/highlighter.vim b/t/highlighter.vim index 0a10c19..a1ed490 100644 --- a/t/highlighter.vim +++ b/t/highlighter.vim @@ -13,6 +13,7 @@ describe 'highlighter' Expect exists('g:airline#themes#dark#palette.normal.airline_c_red') to_be_false Expect hlID('airline_c_red') == 0 call airline#themes#patch(g:airline#themes#dark#palette) + call airline#highlighter#add_accent('red') call airline#highlighter#highlight(['normal']) Expect hlID('airline_c_red') != 0 end