hunks: Make hunk extension slightly faster

do not call airline#extensions#branch#head() but instead use the cached
variable b:airline_head.

Note: it looks like GitGutterGetHunkSummary() could need some cacheing
This commit is contained in:
Christian Brabandt 2017-06-27 14:14:16 +02:00
parent 6ab0098ced
commit 174b7e1962
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09

View File

@ -19,7 +19,8 @@ function! s:get_hunks_signify()
endfunction endfunction
function! s:is_branch_empty() function! s:is_branch_empty()
return exists('*airline#extensions#branch#head') && empty(airline#extensions#branch#head()) return exists('*airline#extensions#branch#head') &&
\ empty(get(b:, 'airline_head', ''))
endfunction endfunction
function! s:get_hunks_gitgutter() function! s:get_hunks_gitgutter()
@ -34,12 +35,7 @@ function! s:get_hunks_changes()
return [] return []
endif endif
let hunks = changes#GetStats() let hunks = changes#GetStats()
for i in hunks return hunks == [0, 0, 0] ? [] : hunks
if i > 0
return hunks
endif
endfor
return []
endfunction endfunction
function! s:get_hunks_empty() function! s:get_hunks_empty()
@ -69,7 +65,7 @@ function! airline#extensions#hunks#get_hunks()
endif endif
" Cache vavlues, so that it isn't called too often " Cache vavlues, so that it isn't called too often
if exists("b:airline_hunks") && if exists("b:airline_hunks") &&
\ get(b:, 'airline_changenr', 0) == changenr() && \ get(b:, 'airline_changenr', 0) == b:changedtick &&
\ winwidth(0) == get(s:, 'airline_winwidth', 0) && \ winwidth(0) == get(s:, 'airline_winwidth', 0) &&
\ get(b:, 'source_func', '') isnot# 's:get_hunks_signify' && \ get(b:, 'source_func', '') isnot# 's:get_hunks_signify' &&
\ get(b:, 'source_func', '') isnot# 's:get_hunks_gitgutter' && \ get(b:, 'source_func', '') isnot# 's:get_hunks_gitgutter' &&
@ -86,7 +82,7 @@ function! airline#extensions#hunks#get_hunks()
endfor endfor
endif endif
let b:airline_hunks = string let b:airline_hunks = string
let b:airline_changenr = changenr() let b:airline_changenr = b:changedtick
let s:airline_winwidth = winwidth(0) let s:airline_winwidth = winwidth(0)
return string return string
endfunction endfunction