From 174b7e1962c9fbb8450a56fa09b11201bd3b7622 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Tue, 27 Jun 2017 14:14:16 +0200 Subject: [PATCH] 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 --- autoload/airline/extensions/hunks.vim | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 02a8ff4..5ccf065 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -19,7 +19,8 @@ function! s:get_hunks_signify() endfunction 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 function! s:get_hunks_gitgutter() @@ -34,12 +35,7 @@ function! s:get_hunks_changes() return [] endif let hunks = changes#GetStats() - for i in hunks - if i > 0 - return hunks - endif - endfor - return [] + return hunks == [0, 0, 0] ? [] : hunks endfunction function! s:get_hunks_empty() @@ -69,7 +65,7 @@ function! airline#extensions#hunks#get_hunks() endif " Cache vavlues, so that it isn't called too often 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) && \ get(b:, 'source_func', '') isnot# 's:get_hunks_signify' && \ get(b:, 'source_func', '') isnot# 's:get_hunks_gitgutter' && @@ -86,7 +82,7 @@ function! airline#extensions#hunks#get_hunks() endfor endif let b:airline_hunks = string - let b:airline_changenr = changenr() + let b:airline_changenr = b:changedtick let s:airline_winwidth = winwidth(0) return string endfunction