mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
updated for version 7.3.454
Problem: Re-allocating memory slows Vim down. Solution: Use realloc() in ga_grow(). (Dominique Pelle)
This commit is contained in:
16
src/misc2.c
16
src/misc2.c
@@ -2064,24 +2064,22 @@ ga_grow(gap, n)
|
|||||||
garray_T *gap;
|
garray_T *gap;
|
||||||
int n;
|
int n;
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t old_len;
|
||||||
|
size_t new_len;
|
||||||
char_u *pp;
|
char_u *pp;
|
||||||
|
|
||||||
if (gap->ga_maxlen - gap->ga_len < n)
|
if (gap->ga_maxlen - gap->ga_len < n)
|
||||||
{
|
{
|
||||||
if (n < gap->ga_growsize)
|
if (n < gap->ga_growsize)
|
||||||
n = gap->ga_growsize;
|
n = gap->ga_growsize;
|
||||||
len = gap->ga_itemsize * (gap->ga_len + n);
|
new_len = gap->ga_itemsize * (gap->ga_len + n);
|
||||||
pp = alloc_clear((unsigned)len);
|
pp = (gap->ga_data == NULL)
|
||||||
|
? alloc(new_len) : vim_realloc(gap->ga_data, new_len);
|
||||||
if (pp == NULL)
|
if (pp == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
old_len = gap->ga_itemsize * gap->ga_maxlen;
|
||||||
|
vim_memset(pp + old_len, 0, new_len - old_len);
|
||||||
gap->ga_maxlen = gap->ga_len + n;
|
gap->ga_maxlen = gap->ga_len + n;
|
||||||
if (gap->ga_data != NULL)
|
|
||||||
{
|
|
||||||
mch_memmove(pp, gap->ga_data,
|
|
||||||
(size_t)(gap->ga_itemsize * gap->ga_len));
|
|
||||||
vim_free(gap->ga_data);
|
|
||||||
}
|
|
||||||
gap->ga_data = pp;
|
gap->ga_data = pp;
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
|
@@ -714,6 +714,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
454,
|
||||||
/**/
|
/**/
|
||||||
453,
|
453,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user