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.
This commit is contained in:
Christian Brabandt 2017-08-11 10:43:30 +02:00
parent 96352f9b53
commit c65d7fe36b
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
1 changed files with 9 additions and 8 deletions

View File

@ -92,10 +92,10 @@ function! airline#highlighter#exec(group, colors)
let colors = s:CheckDefined(colors) let colors = s:CheckDefined(colors)
if old_hi != new_hi || !s:hl_group_exists(a:group) if old_hi != new_hi || !s:hl_group_exists(a:group)
let cmd = printf('hi %s %s %s %s %s %s %s %s', let cmd = printf('hi %s %s %s %s %s %s %s %s',
\ a:group, s:Get(colors, 0, 'guifg=', ''), s:Get(colors, 1, 'guibg=', ''), \ 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, 2, 'ctermfg='), s:Get(colors, 3, 'ctermbg='),
\ s:Get(colors, 4, 'gui=', ''), s:Get(colors, 4, 'cterm=', ''), \ s:Get(colors, 4, 'gui='), s:Get(colors, 4, 'cterm='),
\ s:Get(colors, 4, 'term=', '')) \ s:Get(colors, 4, 'term='))
exe cmd exe cmd
endif endif
endfunction endfunction
@ -132,11 +132,12 @@ function! s:CheckDefined(colors)
return a:colors[0:1] + [fg, bg] + [a:colors[4]] return a:colors[0:1] + [fg, bg] + [a:colors[4]]
endfunction endfunction
function! s:Get(dict, key, prefix, default) function! s:Get(dict, key, prefix)
if get(a:dict, a:key, a:default) isnot# a:default let res=get(a:dict, a:key, '')
return a:prefix. get(a:dict, a:key) if empty(res)
else
return '' return ''
else
return a:prefix. res
endif endif
endfunction endfunction