Skip to content

Commit e358557

Browse files
committed
optimize evaluating expanding components
1 parent d6a07ea commit e358557

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

autoload/lightline.vim

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" Filename: autoload/lightline.vim
33
" Author: itchyny
44
" License: MIT License
5-
" Last Change: 2021/11/21 22:54:46.
5+
" Last Change: 2024/12/30 21:33:02.
66
" =============================================================================
77

88
let s:save_cpo = &cpo
@@ -317,26 +317,13 @@ function! lightline#statusline(inactive) abort
317317
return s:line(0, a:inactive)
318318
endfunction
319319

320-
function! s:normalize(result) abort
321-
if type(a:result) == 3
322-
return map(a:result, 'type(v:val) == 1 ? v:val : string(v:val)')
323-
elseif type(a:result) == 1
324-
return [a:result]
325-
else
326-
return [string(a:result)]
327-
endif
328-
endfunction
329-
330320
function! s:evaluate_expand(component) abort
331-
try
332-
let result = eval(a:component . '()')
333-
if type(result) == 1 && result ==# ''
334-
return []
335-
endif
336-
catch
337-
return []
338-
endtry
339-
return map(type(result) == 3 ? (result + [[], [], []])[:2] : [[], [result], []], 'filter(s:normalize(v:val), "v:val !=# ''''")')
321+
try | let value = eval(a:component . '()') | catch | return [] | endtry
322+
return value is '' ? [] :
323+
\ map(type(value) == 3 ? value : [[], [value], []],
324+
\ 'filter(map(type(v:val) == 3 ? v:val : [v:val],
325+
\ "type(v:val) == 1 ? v:val : string(v:val)"),
326+
\ "v:val !=# ''''")')
340327
endfunction
341328

342329
function! s:convert(name, index) abort
@@ -346,7 +333,8 @@ function! s:convert(name, index) abort
346333
let type = get(s:lightline.component_type, a:name, a:index)
347334
let is_raw = get(s:lightline.component_raw, a:name) || type ==# 'raw'
348335
return filter(map(s:evaluate_expand(s:lightline.component_expand[a:name]),
349-
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') . ' ? "' . type . '" : "' . a:index . '", "' . a:index . '"]'), 'v:val[0] != []')
336+
\ '[v:val, 1 + ' . is_raw . ', v:key == 1 && ' . (type !=# 'raw') .
337+
\ ' ? "' . type . '" : "' . a:index . '", "' . a:index . '"]'), 'v:val[0] != []')
350338
endif
351339
endfunction
352340

0 commit comments

Comments
 (0)