vim-patch:7.4.2018

Problem:  buf_valid() can be slow when there are many buffers.
Solution: Add bufref_valid(), only go through the buffer list
          when a buffer was freed.

b25f9a97e9
This commit is contained in:
Marco Hinz
2017-01-09 02:03:03 +01:00
committed by James McCoy
parent 951dd1571c
commit e177226d51
4 changed files with 119 additions and 52 deletions

View File

@@ -1286,7 +1286,7 @@ void copy_loclist(win_T *from, win_T *to)
// Looking up a buffer can be slow if there are many. Remember the last one to
// make this a lot faster if there are multiple matches in the same file.
static char_u *qf_last_bufname = NULL;
static buf_T *qf_last_buf = NULL;
static bufref_T qf_last_bufref = { NULL, 0 };
// Get buffer number for file "directory.fname".
// Also sets the b_has_qf_entry flag.
@@ -1328,14 +1328,14 @@ static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname)
if (qf_last_bufname != NULL
&& STRCMP(bufname, qf_last_bufname) == 0
&& buf_valid(qf_last_buf)) {
buf = qf_last_buf;
&& bufref_valid(&qf_last_bufref)) {
buf = qf_last_bufref.br_buf;
xfree(ptr);
} else {
xfree(qf_last_bufname);
buf = buflist_new(bufname, NULL, (linenr_T)0, BLN_NOOPT);
qf_last_bufname = (bufname == ptr) ? bufname : vim_strsave(bufname);
qf_last_buf = buf;
set_bufref(&qf_last_bufref, buf);
}
if (buf == NULL) {
return 0;