mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:7.4.1841
Problem: The code to reallocate the buffer used for quickfix is repeated.
Solution: Move the code to a function. (Yegappan Lakshmanan, closes vim/vim#831)
2b2b8ae5ab
This commit is contained in:
parent
e2b081ed0c
commit
9df9cf4ecc
@ -171,6 +171,22 @@ qf_init (
|
|||||||
// Maximum number of bytes allowed per line while reading an errorfile.
|
// Maximum number of bytes allowed per line while reading an errorfile.
|
||||||
static const size_t LINE_MAXLEN = 4096;
|
static const size_t LINE_MAXLEN = 4096;
|
||||||
|
|
||||||
|
static char_u *qf_grow_linebuf(char_u **growbuf, size_t *growbufsiz,
|
||||||
|
size_t newsz, size_t *allocsz)
|
||||||
|
{
|
||||||
|
// If the line exceeds LINE_MAXLEN exclude the last
|
||||||
|
// byte since it's not a NL character.
|
||||||
|
*allocsz = newsz > LINE_MAXLEN ? LINE_MAXLEN - 1 : newsz;
|
||||||
|
if (*growbuf == NULL) {
|
||||||
|
*growbuf = xmalloc(*allocsz + 1);
|
||||||
|
*growbufsiz = *allocsz;
|
||||||
|
} else if (*allocsz > *growbufsiz) {
|
||||||
|
*growbuf = xrealloc(*growbuf, *allocsz + 1);
|
||||||
|
*growbufsiz = *allocsz;
|
||||||
|
}
|
||||||
|
return *growbuf;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read the errorfile "efile" into memory, line by line, building the error
|
* Read the errorfile "efile" into memory, line by line, building the error
|
||||||
* list.
|
* list.
|
||||||
@ -488,16 +504,7 @@ qf_init_ext (
|
|||||||
len = STRLEN(p_str);
|
len = STRLEN(p_str);
|
||||||
|
|
||||||
if (len > IOSIZE - 2) {
|
if (len > IOSIZE - 2) {
|
||||||
// If the line exceeds LINE_MAXLEN exclude the last byte since it's
|
linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, &linelen);
|
||||||
// not a NL character.
|
|
||||||
linelen = len > LINE_MAXLEN ? LINE_MAXLEN - 1 : len;
|
|
||||||
if (growbuf == NULL) {
|
|
||||||
growbuf = xmalloc(linelen + 1);
|
|
||||||
} else if (linelen > growbufsiz) {
|
|
||||||
growbuf = xrealloc(growbuf, linelen + 1);
|
|
||||||
}
|
|
||||||
growbufsiz = linelen;
|
|
||||||
linebuf = growbuf;
|
|
||||||
} else {
|
} else {
|
||||||
linebuf = IObuff;
|
linebuf = IObuff;
|
||||||
linelen = len;
|
linelen = len;
|
||||||
@ -520,18 +527,7 @@ qf_init_ext (
|
|||||||
|
|
||||||
len = STRLEN(p_li->li_tv.vval.v_string);
|
len = STRLEN(p_li->li_tv.vval.v_string);
|
||||||
if (len > IOSIZE - 2) {
|
if (len > IOSIZE - 2) {
|
||||||
linelen = len;
|
linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, &linelen);
|
||||||
if (linelen > LINE_MAXLEN) {
|
|
||||||
linelen = LINE_MAXLEN - 1;
|
|
||||||
}
|
|
||||||
if (growbuf == NULL) {
|
|
||||||
growbuf = xmalloc(linelen + 1);
|
|
||||||
growbufsiz = linelen;
|
|
||||||
} else if (linelen > growbufsiz) {
|
|
||||||
growbuf = xrealloc(growbuf, linelen + 1);
|
|
||||||
growbufsiz = linelen;
|
|
||||||
}
|
|
||||||
linebuf = growbuf;
|
|
||||||
} else {
|
} else {
|
||||||
linebuf = IObuff;
|
linebuf = IObuff;
|
||||||
linelen = len;
|
linelen = len;
|
||||||
@ -548,17 +544,7 @@ qf_init_ext (
|
|||||||
p_buf = ml_get_buf(buf, buflnum++, false);
|
p_buf = ml_get_buf(buf, buflnum++, false);
|
||||||
linelen = STRLEN(p_buf);
|
linelen = STRLEN(p_buf);
|
||||||
if (linelen > IOSIZE - 2) {
|
if (linelen > IOSIZE - 2) {
|
||||||
if (growbuf == NULL) {
|
linebuf = qf_grow_linebuf(&growbuf, &growbufsiz, len, &linelen);
|
||||||
growbuf = xmalloc(linelen + 1);
|
|
||||||
growbufsiz = linelen;
|
|
||||||
} else if (linelen > growbufsiz) {
|
|
||||||
if (linelen > LINE_MAXLEN) {
|
|
||||||
linelen = LINE_MAXLEN - 1;
|
|
||||||
}
|
|
||||||
growbuf = xrealloc(growbuf, linelen + 1);
|
|
||||||
growbufsiz = linelen;
|
|
||||||
}
|
|
||||||
linebuf = growbuf;
|
|
||||||
} else {
|
} else {
|
||||||
linebuf = IObuff;
|
linebuf = IObuff;
|
||||||
}
|
}
|
||||||
|
@ -682,14 +682,14 @@ endfunc
|
|||||||
|
|
||||||
" Tests for the setqflist() and setloclist() functions
|
" Tests for the setqflist() and setloclist() functions
|
||||||
function SetXlistTests(cchar, bnum)
|
function SetXlistTests(cchar, bnum)
|
||||||
|
let Xwindow = a:cchar . 'window'
|
||||||
|
let Xnext = a:cchar . 'next'
|
||||||
if a:cchar == 'c'
|
if a:cchar == 'c'
|
||||||
let Xsetlist = function('setqflist')
|
let Xsetlist = function('setqflist')
|
||||||
let Xgetlist = function('getqflist')
|
let Xgetlist = function('getqflist')
|
||||||
let Xnext = 'cnext'
|
|
||||||
else
|
else
|
||||||
let Xsetlist = function('setloclist', [0])
|
let Xsetlist = function('setloclist', [0])
|
||||||
let Xgetlist = function('getloclist', [0])
|
let Xgetlist = function('getloclist', [0])
|
||||||
let Xnext = 'lnext'
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
|
call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
|
||||||
@ -705,6 +705,15 @@ function SetXlistTests(cchar, bnum)
|
|||||||
exe Xnext
|
exe Xnext
|
||||||
call assert_equal(3, line('.'))
|
call assert_equal(3, line('.'))
|
||||||
|
|
||||||
|
" Appending entries to the list should not change the cursor position
|
||||||
|
" in the quickfix window
|
||||||
|
exe Xwindow
|
||||||
|
1
|
||||||
|
call Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
|
||||||
|
\ {'bufnr': a:bnum, 'lnum': 5}], 'a')
|
||||||
|
call assert_equal(1, line('.'))
|
||||||
|
close
|
||||||
|
|
||||||
call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
|
call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
|
||||||
\ {'bufnr': a:bnum, 'lnum': 4},
|
\ {'bufnr': a:bnum, 'lnum': 4},
|
||||||
\ {'bufnr': a:bnum, 'lnum': 5}], 'r')
|
\ {'bufnr': a:bnum, 'lnum': 5}], 'r')
|
||||||
|
@ -599,7 +599,7 @@ static int included_patches[] = {
|
|||||||
// 1844,
|
// 1844,
|
||||||
// 1843 NA
|
// 1843 NA
|
||||||
1842,
|
1842,
|
||||||
// 1841,
|
1841,
|
||||||
1840,
|
1840,
|
||||||
// 1839,
|
// 1839,
|
||||||
// 1838,
|
// 1838,
|
||||||
|
Loading…
Reference in New Issue
Block a user