diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-04-08 18:41:13 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-04-08 18:41:13 +0200 |
commit | d34f9b1155a6b470e1dc766ff98192f440e7eba7 (patch) | |
tree | a4f8d191d0d3727d184a95eeef715d5c9c339d21 | |
parent | 9585a1655ba0d34ea88574617112093a9bd4f2e9 (diff) | |
download | vim-git-d34f9b1155a6b470e1dc766ff98192f440e7eba7.tar.gz |
patch 8.0.0551: the typeahead buffer is reallocated too oftenv8.0.0551
Problem: The typeahead buffer is reallocated too often.
Solution: Re-use the existing buffer if possible.
-rw-r--r-- | src/getchar.c | 16 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 15 insertions, 3 deletions
diff --git a/src/getchar.c b/src/getchar.c index c057861a6..18af2a374 100644 --- a/src/getchar.c +++ b/src/getchar.c @@ -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; } } @@ -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. */ @@ -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; diff --git a/src/version.c b/src/version.c index aba7a80f5..2ea57088a 100644 --- a/src/version.c +++ b/src/version.c @@ -765,6 +765,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 551, +/**/ 550, /**/ 549, |