aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2018-06-19 18:56:55 -0400
committerJustin M. Keyes <justinkz@gmail.com>2018-06-20 00:56:55 +0200
commitb36aba98408b88be3edd815fee88e969e1a4c081 (patch)
tree69c9505309e927de4d29c570d3b2850528cc2982 /src
parentf389fea8fab5f09fd2a5d82ecbc47c60a5850c5f (diff)
downloadrneovim-b36aba98408b88be3edd815fee88e969e1a4c081.tar.gz
rneovim-b36aba98408b88be3edd815fee88e969e1a4c081.tar.bz2
rneovim-b36aba98408b88be3edd815fee88e969e1a4c081.zip
vim-patch:8.0.0551: the typeahead buffer is reallocated too often (#8598)
Problem: The typeahead buffer is reallocated too often. Solution: Re-use the existing buffer if possible. https://github.com/vim/vim/commit/d34f9b1155a6b470e1dc766ff98192f440e7eba7
Diffstat (limited to 'src')
-rw-r--r--src/nvim/getchar.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 1c0464b575..a77c467fe5 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -835,7 +835,7 @@ static void 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;
}
}
@@ -879,9 +879,15 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent)
// Easy case: there is room in front of typebuf.tb_buf[typebuf.tb_off]
typebuf.tb_off -= addlen;
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;
+ 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.
newoff = MAXMAPLEN + 4;
@@ -1145,7 +1151,7 @@ void alloc_typebuf(void)
typebuf.tb_buf = xmalloc(TYPELEN_INIT);
typebuf.tb_noremap = xmalloc(TYPELEN_INIT);
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;