improve performance of lightline#highlight()

This commit is contained in:
itchyny
2013-10-31 21:54:34 +09:00
parent 150c9f9da7
commit 5887a9ad0b

View File

@@ -137,6 +137,19 @@ function! s:term(l)
return len(a:l) == 5 && type(a:l[4]) == 1 && strlen(a:l[4]) ? 'term='.a:l[4].' cterm='.a:l[4].' gui='.a:l[4] : ''
endfunction
function! s:uniq(l)
let [l,i,s] = [a:l,0,{}]
while i < len(l)
let k = string(l[i])
if has_key(s, k)
call remove(l, i)
else
let [s[k],i] = [1,i+1]
endif
endwhile
return l
endfunction
function! lightline#highlight()
let [c, f, g] = [s:lightline.palette, s:lightline.mode_fallback, s:lightline.component_type]
if (has('win32') || has('win64')) && !has('gui_running')
@@ -148,7 +161,7 @@ function! lightline#highlight()
endif
let [s:lightline.llen, s:lightline.rlen] = [len(c.normal.left), len(c.normal.right)]
let [s:lightline.tab_llen, s:lightline.tab_rlen] = [len(has_key(c,'tabline') && has_key(c.tabline, 'left') ? c.tabline.left : c.normal.left), len(has_key(c,'tabline') && has_key(c.tabline, 'right') ? c.tabline.right : c.normal.right)]
let h = filter(copy(values(g)), 'v:val !=# "raw"')
let h = s:uniq(filter(copy(values(g)), 'v:val !=# "raw"'))
for mode in ['normal', 'insert', 'replace', 'visual', 'inactive', 'command', 'select', 'tabline']
let d = has_key(c, mode) ? mode : has_key(f, mode) && has_key(c, f[mode]) ? f[mode] : 'normal'
let left = d == 'tabline' ? s:lightline.tabline.left : d == 'inactive' ? s:lightline.inactive.left : s:lightline.active.left