From c65d7fe36b9d4d6f779725be86d71c4aa0257e01 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Fri, 11 Aug 2017 10:43:30 +0200 Subject: [PATCH] highlighter: slight performance increase do not access get() function twice. We can assign the result to a variable and use it a second time. Should speed up the highligther part of the code by a bit. Since I was already touching s:Get(), also get rid of the default parameter, as it always has been the empty string. --- autoload/airline/highlighter.vim | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/autoload/airline/highlighter.vim b/autoload/airline/highlighter.vim index 631f311..485045d 100644 --- a/autoload/airline/highlighter.vim +++ b/autoload/airline/highlighter.vim @@ -92,10 +92,10 @@ function! airline#highlighter#exec(group, colors) let colors = s:CheckDefined(colors) if old_hi != new_hi || !s:hl_group_exists(a:group) let cmd = printf('hi %s %s %s %s %s %s %s %s', - \ a:group, s:Get(colors, 0, 'guifg=', ''), s:Get(colors, 1, 'guibg=', ''), - \ s:Get(colors, 2, 'ctermfg=', ''), s:Get(colors, 3, 'ctermbg=', ''), - \ s:Get(colors, 4, 'gui=', ''), s:Get(colors, 4, 'cterm=', ''), - \ s:Get(colors, 4, 'term=', '')) + \ a:group, s:Get(colors, 0, 'guifg='), s:Get(colors, 1, 'guibg='), + \ s:Get(colors, 2, 'ctermfg='), s:Get(colors, 3, 'ctermbg='), + \ s:Get(colors, 4, 'gui='), s:Get(colors, 4, 'cterm='), + \ s:Get(colors, 4, 'term=')) exe cmd endif endfunction @@ -132,11 +132,12 @@ function! s:CheckDefined(colors) return a:colors[0:1] + [fg, bg] + [a:colors[4]] endfunction -function! s:Get(dict, key, prefix, default) - if get(a:dict, a:key, a:default) isnot# a:default - return a:prefix. get(a:dict, a:key) - else +function! s:Get(dict, key, prefix) + let res=get(a:dict, a:key, '') + if empty(res) return '' + else + return a:prefix. res endif endfunction