Skip to content

Commit

Permalink
patch 8.0.0551: the typeahead buffer is reallocated too often
Browse files Browse the repository at this point in the history
Problem:    The typeahead buffer is reallocated too often.
Solution:   Re-use the existing buffer if possible.
  • Loading branch information
brammool committed Apr 8, 2017
1 parent 9585a16 commit d34f9b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ init_typebuf(void)
typebuf.tb_noremap = noremapbuf_init;
typebuf.tb_buflen = TYPELEN_INIT;
typebuf.tb_len = 0;
typebuf.tb_off = 0;
typebuf.tb_off = MAXMAPLEN + 4;
typebuf.tb_change_cnt = 1;
}
}
Expand Down Expand Up @@ -974,11 +974,21 @@ ins_typebuf(
typebuf.tb_off -= addlen;
mch_memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen);
}
else if (typebuf.tb_len == 0 && typebuf.tb_buflen
>= addlen + 3 * (MAXMAPLEN + 4))
{
/*
* Buffer is empty and string fits in the existing buffer.
* Leave some space before and after, if possible.
*/
typebuf.tb_off = (typebuf.tb_buflen - addlen - 3 * (MAXMAPLEN + 4)) / 2;
mch_memmove(typebuf.tb_buf + typebuf.tb_off, str, (size_t)addlen);
}
else
{
/*
* Need to allocate a new buffer.
* In typebuf.tb_buf there must always be room for 3 * MAXMAPLEN + 4
* In typebuf.tb_buf there must always be room for 3 * (MAXMAPLEN + 4)
* characters. We add some extra room to avoid having to allocate too
* often.
*/
Expand Down Expand Up @@ -1291,7 +1301,7 @@ alloc_typebuf(void)
return FAIL;
}
typebuf.tb_buflen = TYPELEN_INIT;
typebuf.tb_off = 0;
typebuf.tb_off = MAXMAPLEN + 4; /* can insert without realloc */
typebuf.tb_len = 0;
typebuf.tb_maplen = 0;
typebuf.tb_silent = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
551,
/**/
550,
/**/
Expand Down

0 comments on commit d34f9b1

Please sign in to comment.