comparison src/quickfix.c @ 9487:69ed2c9d34a6 v7.4.2024

commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 10 22:11:16 2016 +0200 patch 7.4.2024 Problem: More buf_valid() calls can be optimized. Solution: Use bufref_valid() instead.
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Jul 2016 22:15:06 +0200
parents c16e207dc465
children 50697f3b49d6
comparison
equal deleted inserted replaced
9486:b931ed8a6782 9487:69ed2c9d34a6
4240 char_u *fname, 4240 char_u *fname,
4241 char_u *dirname_start, /* in: old directory */ 4241 char_u *dirname_start, /* in: old directory */
4242 char_u *resulting_dir) /* out: new directory */ 4242 char_u *resulting_dir) /* out: new directory */
4243 { 4243 {
4244 buf_T *newbuf; 4244 buf_T *newbuf;
4245 buf_T *newbuf_to_wipe = NULL; 4245 bufref_T newbufref;
4246 bufref_T newbuf_to_wipe;
4246 int failed = TRUE; 4247 int failed = TRUE;
4247 aco_save_T aco; 4248 aco_save_T aco;
4248 4249
4249 /* Allocate a buffer without putting it in the buffer list. */ 4250 /* Allocate a buffer without putting it in the buffer list. */
4250 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); 4251 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
4251 if (newbuf == NULL) 4252 if (newbuf == NULL)
4252 return NULL; 4253 return NULL;
4254 set_bufref(&newbufref, newbuf);
4253 4255
4254 /* Init the options. */ 4256 /* Init the options. */
4255 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP); 4257 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
4256 4258
4257 /* need to open the memfile before putting the buffer in a window */ 4259 /* need to open the memfile before putting the buffer in a window */
4268 4270
4269 /* Remove the "dummy" flag, otherwise autocommands may not 4271 /* Remove the "dummy" flag, otherwise autocommands may not
4270 * work. */ 4272 * work. */
4271 curbuf->b_flags &= ~BF_DUMMY; 4273 curbuf->b_flags &= ~BF_DUMMY;
4272 4274
4275 newbuf_to_wipe.br_buf = NULL;
4273 if (readfile(fname, NULL, 4276 if (readfile(fname, NULL,
4274 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, 4277 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
4275 NULL, READ_NEW | READ_DUMMY) == OK 4278 NULL, READ_NEW | READ_DUMMY) == OK
4276 && !got_int 4279 && !got_int
4277 && !(curbuf->b_flags & BF_NEW)) 4280 && !(curbuf->b_flags & BF_NEW))
4281 { 4284 {
4282 /* Bloody autocommands changed the buffer! Can happen when 4285 /* Bloody autocommands changed the buffer! Can happen when
4283 * using netrw and editing a remote file. Use the current 4286 * using netrw and editing a remote file. Use the current
4284 * buffer instead, delete the dummy one after restoring the 4287 * buffer instead, delete the dummy one after restoring the
4285 * window stuff. */ 4288 * window stuff. */
4286 newbuf_to_wipe = newbuf; 4289 set_bufref(&newbuf_to_wipe, newbuf);
4287 newbuf = curbuf; 4290 newbuf = curbuf;
4288 } 4291 }
4289 } 4292 }
4290 4293
4291 /* restore curwin/curbuf and a few other things */ 4294 /* restore curwin/curbuf and a few other things */
4292 aucmd_restbuf(&aco); 4295 aucmd_restbuf(&aco);
4293 if (newbuf_to_wipe != NULL && buf_valid(newbuf_to_wipe)) 4296 if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe))
4294 wipe_buffer(newbuf_to_wipe, FALSE); 4297 wipe_buffer(newbuf_to_wipe.br_buf, FALSE);
4295 4298
4296 /* Add back the "dummy" flag, otherwise buflist_findname_stat() won't 4299 /* Add back the "dummy" flag, otherwise buflist_findname_stat() won't
4297 * skip it. */ 4300 * skip it. */
4298 newbuf->b_flags |= BF_DUMMY; 4301 newbuf->b_flags |= BF_DUMMY;
4299 } 4302 }
4304 * important. 4307 * important.
4305 */ 4308 */
4306 mch_dirname(resulting_dir, MAXPATHL); 4309 mch_dirname(resulting_dir, MAXPATHL);
4307 restore_start_dir(dirname_start); 4310 restore_start_dir(dirname_start);
4308 4311
4309 if (!buf_valid(newbuf)) 4312 if (!bufref_valid(&newbufref))
4310 return NULL; 4313 return NULL;
4311 if (failed) 4314 if (failed)
4312 { 4315 {
4313 wipe_dummy_buffer(newbuf, dirname_start); 4316 wipe_dummy_buffer(newbuf, dirname_start);
4314 return NULL; 4317 return NULL;