diff src/buffer.c @ 9485:c16e207dc465 v7.4.2023

commit https://github.com/vim/vim/commit/ea3f2e7be447a8f0c4436869620f908de5e8ef1e Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 10 20:27:32 2016 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Sun, 10 Jul 2016 20:30:06 +0200
parents 7520696c14b0
children 69ed2c9d34a6
line wrap: on
line diff
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -2270,7 +2270,8 @@ buflist_findname_stat(
 #endif
     buf_T	*buf;
 
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    /* Start at the last buffer, expect to find a match sooner. */
+    for (buf = lastbuf; buf != NULL; buf = buf->b_prev)
 	if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname
 #ifdef UNIX
 		    , stp
@@ -2355,7 +2356,7 @@ buflist_findpat(
 		    return -1;
 		}
 
-		for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+		for (buf = lastbuf; buf != NULL; buf = buf->b_prev)
 		    if (buf->b_p_bl == find_listed
 #ifdef FEAT_DIFF
 			    && (!diffmode || diff_mode_buf(buf))
@@ -2581,7 +2582,8 @@ buflist_findnr(int nr)
 
     if (nr == 0)
 	nr = curwin->w_alt_fnum;
-    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
+    /* Assume newer buffers are used more often, start from the end. */
+    for (buf = lastbuf; buf != NULL; buf = buf->b_prev)
 	if (buf->b_fnum == nr)
 	    return buf;
     return NULL;