• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revision90e5812af76ba00506ab9316af7d8bbb2f2f0b2f (tree)
Time2019-11-08 07:15:04
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.1.2269: tags file with very long line stops using binary search

Commit: https://github.com/vim/vim/commit/dc9ef26845c6bf5ba63bfa8d00fc8a9bdc3b2de5
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Nov 7 23:08:42 2019 +0100

patch 8.1.2269: tags file with very long line stops using binary search
Problem: Tags file with very long line stops using binary search.
Solution: Reallocate the buffer if needed.

Change Summary

Incremental Difference

diff -r 8ce88501264f -r 90e5812af76b src/tag.c
--- a/src/tag.c Thu Nov 07 21:00:05 2019 +0100
+++ b/src/tag.c Thu Nov 07 23:15:04 2019 +0100
@@ -1937,7 +1937,7 @@
19371937 */
19381938 else if (state == TS_SKIP_BACK)
19391939 {
1940- search_info.curr_offset -= LSIZE * 2;
1940+ search_info.curr_offset -= lbuf_size * 2;
19411941 if (search_info.curr_offset < 0)
19421942 {
19431943 search_info.curr_offset = 0;
@@ -1955,7 +1955,7 @@
19551955 /* Adjust the search file offset to the correct position */
19561956 search_info.curr_offset_used = search_info.curr_offset;
19571957 vim_fseek(fp, search_info.curr_offset, SEEK_SET);
1958- eof = vim_fgets(lbuf, LSIZE, fp);
1958+ eof = vim_fgets(lbuf, lbuf_size, fp);
19591959 if (!eof && search_info.curr_offset != 0)
19601960 {
19611961 /* The explicit cast is to work around a bug in gcc 3.4.2
@@ -1967,13 +1967,13 @@
19671967 vim_fseek(fp, search_info.low_offset, SEEK_SET);
19681968 search_info.curr_offset = search_info.low_offset;
19691969 }
1970- eof = vim_fgets(lbuf, LSIZE, fp);
1970+ eof = vim_fgets(lbuf, lbuf_size, fp);
19711971 }
19721972 /* skip empty and blank lines */
19731973 while (!eof && vim_isblankline(lbuf))
19741974 {
19751975 search_info.curr_offset = vim_ftell(fp);
1976- eof = vim_fgets(lbuf, LSIZE, fp);
1976+ eof = vim_fgets(lbuf, lbuf_size, fp);
19771977 }
19781978 if (eof)
19791979 {
@@ -1996,10 +1996,10 @@
19961996 {
19971997 #ifdef FEAT_CSCOPE
19981998 if (use_cscope)
1999- eof = cs_fgets(lbuf, LSIZE);
1999+ eof = cs_fgets(lbuf, lbuf_size);
20002000 else
20012001 #endif
2002- eof = vim_fgets(lbuf, LSIZE, fp);
2002+ eof = vim_fgets(lbuf, lbuf_size, fp);
20032003 } while (!eof && vim_isblankline(lbuf));
20042004
20052005 if (eof)
@@ -2230,28 +2230,21 @@
22302230 // When the line is too long the NUL will not be in the
22312231 // last-but-one byte (see vim_fgets()).
22322232 // Has been reported for Mozilla JS with extremely long names.
2233- // In that case we can't parse it and we ignore the line.
2234- if (lbuf[LSIZE - 2] != NUL
2233+ // In that case we need to increase lbuf_size.
2234+ if (lbuf[lbuf_size - 2] != NUL
22352235 #ifdef FEAT_CSCOPE
22362236 && !use_cscope
22372237 #endif
22382238 )
22392239 {
2240- if (p_verbose >= 5)
2241- {
2242- verbose_enter();
2243- msg(_("Ignoring long line in tags file"));
2244- verbose_leave();
2245- }
2246-#ifdef FEAT_TAG_BINS
2247- if (state != TS_LINEAR)
2248- {
2249- // Avoid getting stuck.
2250- linear = TRUE;
2251- state = TS_LINEAR;
2252- vim_fseek(fp, search_info.low_offset, SEEK_SET);
2253- }
2254-#endif
2240+ lbuf_size *= 2;
2241+ vim_free(lbuf);
2242+ lbuf = alloc(lbuf_size);
2243+ if (lbuf == NULL)
2244+ goto findtag_end;
2245+ // this will try the same thing again, make sure the offset is
2246+ // different
2247+ search_info.curr_offset = 0;
22552248 continue;
22562249 }
22572250
@@ -3367,6 +3360,8 @@
33673360 break;
33683361 #endif
33693362 *pbuf_end++ = *str++;
3363+ if (pbuf_end - pbuf + 1 >= LSIZE)
3364+ break;
33703365 }
33713366 *pbuf_end = NUL;
33723367
diff -r 8ce88501264f -r 90e5812af76b src/testdir/test_tagjump.vim
--- a/src/testdir/test_tagjump.vim Thu Nov 07 21:00:05 2019 +0100
+++ b/src/testdir/test_tagjump.vim Thu Nov 07 23:15:04 2019 +0100
@@ -459,7 +459,8 @@
459459 call assert_report(v:exception)
460460 catch /.*/
461461 endtry
462- call assert_equal('Ignoring long line in tags file', split(execute('messages'), '\n')[-1])
462+ call assert_equal('Searching tags file Xtags', split(execute('messages'), '\n')[-1])
463+
463464 call writefile([
464465 \ '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 django/contrib/admin/templates/admin/edit_inline/stacked.html 16;" j line:16 language:HTML'
465466 \ ], 'Xtags')
@@ -470,8 +471,26 @@
470471 call assert_report(v:exception)
471472 catch /.*/
472473 endtry
473- call assert_equal('Ignoring long line in tags file', split(execute('messages'), '\n')[-1])
474+ call assert_equal('Searching tags file Xtags', split(execute('messages'), '\n')[-1])
475+
476+ " binary search works in file with long line
477+ call writefile([
478+ \ 'asdfasfd nowhere 16',
479+ \ 'foobar Xsomewhere 3; " 12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567',
480+ \ 'zasdfasfd nowhere 16',
481+ \ ], 'Xtags')
482+ call writefile([
483+ \ 'one',
484+ \ 'two',
485+ \ 'trhee',
486+ \ 'four',
487+ \ ], 'Xsomewhere')
488+ tag foobar
489+ call assert_equal('Xsomewhere', expand('%'))
490+ call assert_equal(3, getcurpos()[1])
491+
474492 call delete('Xtags')
493+ call delete('Xsomewhere')
475494 set tags&
476495 let &verbose = old_vbs
477496 endfunc
diff -r 8ce88501264f -r 90e5812af76b src/version.c
--- a/src/version.c Thu Nov 07 21:00:05 2019 +0100
+++ b/src/version.c Thu Nov 07 23:15:04 2019 +0100
@@ -742,6 +742,8 @@
742742 static int included_patches[] =
743743 { /* Add new patch number below this line */
744744 /**/
745+ 2269,
746+/**/
745747 2268,
746748 /**/
747749 2267,
Show on old repository browser