From 951dd1571cbb57b41274c0e515e2b3c789305bad Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sun, 8 Jan 2017 16:53:08 +0100 Subject: vim-patch:7.4.2017 Problem: When there are many errors adding them to the quickfix list takes a long time. Solution: Add BLN_NOOPT. Don't call buf_valid() in buf_copy_options(). Remember the last file name used. When going through the buffer list start from the end of the list. Only call buf_valid() when autocommands were executed. https://github.com/vim/vim/commit/8240433f48f7383c281ba2453cc55f10b8ec47d9 --- src/nvim/quickfix.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/nvim/quickfix.c') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index cebff5e8b7..7b22c95967 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -1283,11 +1283,17 @@ void copy_loclist(win_T *from, win_T *to) to->w_llist->qf_curlist = qi->qf_curlist; /* current list */ } +// 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; + // Get buffer number for file "directory.fname". // Also sets the b_has_qf_entry flag. static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname) { - char_u *ptr; + char_u *ptr = NULL; + char_u *bufname; buf_T *buf; if (fname == NULL || *fname == NUL) { // no file name return 0; @@ -1314,11 +1320,22 @@ static int qf_get_fnum(qf_info_T *qi, char_u *directory, char_u *fname) ptr = vim_strsave(fname); } } - // Use concatenated directory name and file name - buf = buflist_new(ptr, NULL, (linenr_T)0, 0); + // Use concatenated directory name and file name. + bufname = ptr; + } else { + bufname = fname; + } + + if (qf_last_bufname != NULL + && STRCMP(bufname, qf_last_bufname) == 0 + && buf_valid(qf_last_buf)) { + buf = qf_last_buf; xfree(ptr); } else { - buf = buflist_new(fname, NULL, (linenr_T)0, 0); + 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; } if (buf == NULL) { return 0; -- cgit From e177226d51feb99e159773eebe6a773732fc89e9 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 9 Jan 2017 02:03:03 +0100 Subject: 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. https://github.com/vim/vim/commit/b25f9a97e9aad3cbb4bc3fe87cdbd5700f8aa0c6 --- src/nvim/quickfix.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/quickfix.c') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 7b22c95967..4e582108c5 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -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; -- cgit From e3b92c77da0277c8d58e037e42c5b929be469284 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 9 Jan 2017 12:53:06 +0100 Subject: vim-patch:7.4.2023 Problem: buflist_findname_stat() may find a dummy buffer. Solution: Set the BF_DUMMY flag after loading a dummy buffer. Start finding buffers from the end of the list. NOTE: In Neovim, buflist_findname_stat() was replaced by buflist_findname_file_id() in c41535d69. https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e --- src/nvim/quickfix.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/nvim/quickfix.c') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 4e582108c5..45982cc68a 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3778,10 +3778,15 @@ load_dummy_buffer ( } } - /* restore curwin/curbuf and a few other things */ + // Restore curwin/curbuf and a few other things. aucmd_restbuf(&aco); - if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) - wipe_buffer(newbuf_to_wipe, FALSE); + if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) { + wipe_buffer(newbuf_to_wipe, false); + } + + // Add back the "dummy" flag, otherwise buflist_findname_file_id() + // won't skip it. + newbuf->b_flags |= BF_DUMMY; } /* -- cgit From c05e7f0fdd15d550cfb1054416a08d4514a4fb7e Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 9 Jan 2017 14:35:04 +0100 Subject: vim-patch:7.4.2024 Problem: More buf_valid() calls can be optimized. Solution: Use bufref_valid() instead. NOTE: Some changes related to channels and the Python and Netbeans interfaces were obviously left out. https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b --- src/nvim/quickfix.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'src/nvim/quickfix.c') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 45982cc68a..259b1b864c 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3734,7 +3734,8 @@ load_dummy_buffer ( ) { buf_T *newbuf; - buf_T *newbuf_to_wipe = NULL; + bufref_T newbufref; + bufref_T newbuf_to_wipe; int failed = TRUE; aco_save_T aco; @@ -3743,6 +3744,7 @@ load_dummy_buffer ( if (newbuf == NULL) { return NULL; } + set_bufref(&newbufref, newbuf); /* Init the options. */ buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); @@ -3762,6 +3764,7 @@ load_dummy_buffer ( * work. */ curbuf->b_flags &= ~BF_DUMMY; + newbuf_to_wipe.br_buf = NULL; if (readfile(fname, NULL, (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, NULL, READ_NEW | READ_DUMMY) == OK @@ -3769,19 +3772,19 @@ load_dummy_buffer ( && !(curbuf->b_flags & BF_NEW)) { failed = FALSE; if (curbuf != newbuf) { - /* Bloody autocommands changed the buffer! Can happen when - * using netrw and editing a remote file. Use the current - * buffer instead, delete the dummy one after restoring the - * window stuff. */ - newbuf_to_wipe = newbuf; + // Bloody autocommands changed the buffer! Can happen when + // using netrw and editing a remote file. Use the current + // buffer instead, delete the dummy one after restoring the + // window stuff. + set_bufref(&newbuf_to_wipe, newbuf); newbuf = curbuf; } } // Restore curwin/curbuf and a few other things. aucmd_restbuf(&aco); - if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) { - wipe_buffer(newbuf_to_wipe, false); + if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) { + wipe_buffer(newbuf_to_wipe.br_buf, false); } // Add back the "dummy" flag, otherwise buflist_findname_file_id() @@ -3797,8 +3800,9 @@ load_dummy_buffer ( os_dirname(resulting_dir, MAXPATHL); restore_start_dir(dirname_start); - if (!buf_valid(newbuf)) + if (!bufref_valid(&newbufref)) { return NULL; + } if (failed) { wipe_dummy_buffer(newbuf, dirname_start); return NULL; -- cgit From b0cf071d437699b9b89e3735b3df41914f302eb1 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 9 Jan 2017 20:49:47 +0100 Subject: Fix clint issues --- src/nvim/quickfix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/quickfix.c') diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index 259b1b864c..c40403e3f6 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3736,7 +3736,7 @@ load_dummy_buffer ( buf_T *newbuf; bufref_T newbufref; bufref_T newbuf_to_wipe; - int failed = TRUE; + int failed = true; aco_save_T aco; // Allocate a buffer without putting it in the buffer list. -- cgit