From 31906ac7b20883502295290371f7c89947dae6e0 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Mon, 8 Feb 2016 20:34:27 +0100 Subject: [PATCH] Some improvements for the buflist implementation This should make the buflist algorithm faster. Also there is an alternative implementation in branch 535 available, which avoids looping over the complete range, I'll stay with the current approach, as it does not depend on BufAdd/BufDelete autocommands. details: instead of testing for buflisted() and bufexists() we only test for buflisted() because, this also tests for the existence of the buffer. Also instead of a second loop of the exclude patterns, we'll join all of them together with '\|' and check if they match the current buffer. The rest of the conditions have been joined into a single condition. This together made up an improvement of Orig: FUNCTION airline#extensions#tabline#buflist#list() Called 94 times Total time: 0.267305 Self time: 0.267305 New: FUNCTION airline#extensions#tabline#buflist#list() Called 85 times Total time: 0.124572 Self time: 0.124572 --- .../airline/extensions/tabline/buflist.vim | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/autoload/airline/extensions/tabline/buflist.vim b/autoload/airline/extensions/tabline/buflist.vim index b74448c..ac17878 100644 --- a/autoload/airline/extensions/tabline/buflist.vim +++ b/autoload/airline/extensions/tabline/buflist.vim @@ -14,25 +14,23 @@ function! airline#extensions#tabline#buflist#list() endif let buffers = [] - let cur = bufnr('%') + " If this is too slow, we can switch to a different algorithm. + " Basically branch 535 already does it, but since it relies on + " BufAdd autocommand, I'd like to avoid this if possible. for nr in range(1, bufnr('$')) - if buflisted(nr) && bufexists(nr) - let toadd = 1 - for ex in s:excludes - if match(bufname(nr), ex) >= 0 - let toadd = 0 - break - endif - endfor - if getbufvar(nr, 'current_syntax') == 'qf' - let toadd = 0 - endif - if s:exclude_preview && getbufvar(nr, '&bufhidden') == 'wipe' && getbufvar(nr, '&buftype') == 'nofile' - let toadd = 0 - endif - if toadd - call add(buffers, nr) + if buflisted(nr) + " Do not add to the bufferlist, if either + " 1) buffername matches exclude pattern + " 2) buffer is a quickfix buffer + " 3) exclude preview windows (if 'bufhidden' == wipe + " and 'buftype' == nofile + if (!empty(s:excludes) && match(bufname(nr), join(s:excludes, '\|')) > -1) || + \ (getbufvar(nr, 'current_syntax') == 'qf') || + \ (s:exclude_preview && getbufvar(nr, '&bufhidden') == 'wipe' + \ && getbufvar(nr, '&buftype') == 'nofile') + continue endif + call add(buffers, nr) endif endfor