highlighter: get rid of s:Get() function
Replace by a function that retuns the to be executed highlighting string Should in theory be a bit faster, since the same function does not have to be called 5 times per highlighting group. It probably is not much better, but here are some random numbers: Profiling: Previously: count total (s) self (s) 199 0.022973 0.009909 let cmd = printf('hi %s %s %s %s %s %s %s %s', a:group, s:Get(colors, 0, 'guifg=')… New: count total (s) self (s) 79 0.010166 0.000862 let cmd = printf('hi %s%s', a:group, s:GetHiCmd(colors))
This commit is contained in:
parent
6c6c6c104f
commit
4d8a06a5a9
@ -121,11 +121,7 @@ function! airline#highlighter#exec(group, colors)
|
|||||||
endif
|
endif
|
||||||
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', a:group, s:GetHiCmd(colors))
|
||||||
\ 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
|
exe cmd
|
||||||
if has_key(s:hl_groups, a:group)
|
if has_key(s:hl_groups, a:group)
|
||||||
let s:hl_groups[a:group] = colors
|
let s:hl_groups[a:group] = colors
|
||||||
@ -165,13 +161,29 @@ 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)
|
function! s:GetHiCmd(list)
|
||||||
let res=get(a:dict, a:key, '')
|
" a:list needs to have 5 items!
|
||||||
if res is ''
|
let res = ''
|
||||||
return ''
|
let i = -1
|
||||||
else
|
while i < 5
|
||||||
return a:prefix. res
|
let i += 1
|
||||||
|
let item = get(a:list, i, '')
|
||||||
|
if item is ''
|
||||||
|
continue
|
||||||
endif
|
endif
|
||||||
|
if i == 0
|
||||||
|
let res .= ' guifg='.item
|
||||||
|
elseif i == 1
|
||||||
|
let res .= ' guibg='.item
|
||||||
|
elseif i == 2
|
||||||
|
let res .= ' ctermfg='.item
|
||||||
|
elseif i == 3
|
||||||
|
let res .= ' ctermbg='.item
|
||||||
|
elseif i == 4
|
||||||
|
let res .= printf(' gui=%s cterm=%s term=%s', item, item, item)
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
return res
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:exec_separator(dict, from, to, inverse, suffix)
|
function! s:exec_separator(dict, from, to, inverse, suffix)
|
||||||
|
Loading…
Reference in New Issue
Block a user