To: vim-dev@vim.org Subject: Patch 5.6.096 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.096 Problem: Unix: When editing many files, startup can be slow. (Paul Ackersviller) Solution: Halve the number of stat() calls used to add a file to the buffer list. Files: src/buffer.c *** ../vim-5.6.95/src/buffer.c Sat Apr 15 18:05:18 2000 --- src/buffer.c Wed Jun 7 19:11:48 2000 *************** *** 31,36 **** --- 31,37 ---- static char_u *buflist_match_try __ARGS((vim_regexp *prog, char_u *name)); static void buflist_setfpos __ARGS((BUF *, linenr_t, colnr_t)); #ifdef UNIX + static BUF *buflist_findname_stat __ARGS((char_u *ffname, struct stat *st)); static int otherfile_buf __ARGS((BUF *buf, char_u *ffname, struct stat *stp)); static void buf_setino __ARGS((BUF *buf)); static int buf_same_ino __ARGS((BUF *buf, struct stat *stp)); *************** *** 802,814 **** int use_curbuf; { BUF *buf; fname_expand(&ffname, &sfname); /* will allocate ffname */ /* * If file name already exists in the list, update the entry. */ ! if (ffname != NULL && (buf = buflist_findname(ffname)) != NULL) { vim_free(ffname); if (lnum != 0) --- 792,818 ---- int use_curbuf; { BUF *buf; + #ifdef UNIX + struct stat st; + #endif fname_expand(&ffname, &sfname); /* will allocate ffname */ + #ifdef UNIX + if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) + st.st_dev = (unsigned)-1; + #endif + /* * If file name already exists in the list, update the entry. */ ! if (ffname != NULL && (buf = ! #ifdef UNIX ! buflist_findname_stat(ffname, &st) ! #else ! buflist_findname(ffname) ! #endif ! ) != NULL) { vim_free(ffname); if (lnum != 0) *************** *** 917,923 **** buf->b_fname = buf->b_sfname; #ifdef UNIX ! buf_setino(buf); #endif buf->b_u_synced = TRUE; buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; --- 921,933 ---- buf->b_fname = buf->b_sfname; #ifdef UNIX ! if (st.st_dev == (unsigned)-1) ! buf->b_dev = -1; ! else ! { ! buf->b_dev = st.st_dev; ! buf->b_ino = st.st_ino; ! } #endif buf->b_u_synced = TRUE; buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; *************** *** 1093,1110 **** buflist_findname(ffname) char_u *ffname; { - BUF *buf; #ifdef UNIX struct stat st; if (mch_stat((char *)ffname, &st) < 0) st.st_dev = (unsigned)-1; #endif for (buf = firstbuf; buf != NULL; buf = buf->b_next) if (!otherfile_buf(buf, ffname #ifdef UNIX ! , &st #endif )) return buf; --- 1103,1132 ---- buflist_findname(ffname) char_u *ffname; { #ifdef UNIX struct stat st; if (mch_stat((char *)ffname, &st) < 0) st.st_dev = (unsigned)-1; + return buflist_findname_stat(ffname, &st); + } + + /* + * Same as buflist_findname(), but pass the stat structure to avoid getting it + * twice for the same file. + */ + static BUF * + buflist_findname_stat(ffname, stp) + char_u *ffname; + struct stat *stp; + { #endif + BUF *buf; for (buf = firstbuf; buf != NULL; buf = buf->b_next) if (!otherfile_buf(buf, ffname #ifdef UNIX ! , stp #endif )) return buf; *************** *** 1536,1542 **** char_u *ffname, *sfname; int message; { ! BUF *buf; if (ffname == NULL || *ffname == NUL) { --- 1558,1567 ---- char_u *ffname, *sfname; int message; { ! BUF *buf; ! #ifdef UNIX ! struct stat st; ! #endif if (ffname == NULL || *ffname == NUL) { *************** *** 1544,1549 **** --- 1569,1577 ---- vim_free(curbuf->b_sfname); curbuf->b_ffname = NULL; curbuf->b_sfname = NULL; + #ifdef UNIX + st.st_dev = (unsigned)-1; + #endif } else { *************** *** 1562,1568 **** --- 1590,1602 ---- * - if the buffer is loaded, fail * - if the buffer is not loaded, delete it from the list */ + #ifdef UNIX + if (mch_stat((char *)ffname, &st) < 0) + st.st_dev = (unsigned)-1; + buf = buflist_findname_stat(ffname, &st); + #else buf = buflist_findname(ffname); + #endif if (buf != NULL && buf != curbuf) { if (buf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ *************** *** 1588,1594 **** } curbuf->b_fname = curbuf->b_sfname; #ifdef UNIX ! buf_setino(curbuf); #endif #ifndef SHORT_FNAME --- 1622,1634 ---- } curbuf->b_fname = curbuf->b_sfname; #ifdef UNIX ! if (st.st_dev == (unsigned)-1) ! curbuf->b_dev = -1; ! else ! { ! curbuf->b_dev = st.st_dev; ! curbuf->b_ino = st.st_ino; ! } #endif #ifndef SHORT_FNAME *** ../vim-5.6.95/src/version.c Thu Jun 8 21:01:00 2000 --- src/version.c Thu Jun 8 21:01:56 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 96, /**/ -- Engineers are widely recognized as superior marriage material: intelligent, dependable, employed, honest, and handy around the house. (Scott Adams - The Dilbert principle) /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/