vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit f514cebb9f1f6cb62944b85de39c37529817c0b2 parent 4c1dacde513a2c8ef9fbbb685fdfd2f7a34b6f40 Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 20 Nov 2015 15:35:37 +0100 buffer: tweak memory allocation strategy Do not simply double the requested size. Instead take the maximum of - the requested size - double the current buffer size This will use less memory for large register operations (e.g. deleting the whole file). Diffstat:
| M | buffer.c | | | 5 | +---- |
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/buffer.c b/buffer.c @@ -15,10 +15,7 @@ bool buffer_grow(Buffer *buf, size_t size) { if (size < BUF_SIZE) size = BUF_SIZE; if (buf->size < size) { - /* if this is not the first allocation i.e. the buffer is - * currently full, double the size to avoid memory pressure */ - if (buf->size > 0) - size *= 2; + size = MAX(size, buf->size*2); char *data = realloc(buf->data, size); if (!data) return false;