From: Kevin McCarthy Date: Sat, 26 May 2018 21:46:16 +0000 (-0700) Subject: Create mutt_buffer_increase_size() function X-Git-Tag: 2019-10-25~671^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3451f2fd99ba3ee19796dbe43b2a0fe2c42a0b1;p=neomutt Create mutt_buffer_increase_size() function This will allow preallocating buffers that we know are going to be big for qresync support. This will also be useful for buffer pools later on. --- diff --git a/mutt/buffer.c b/mutt/buffer.c index b47bb8abf..3cb89c210 100644 --- a/mutt/buffer.c +++ b/mutt/buffer.c @@ -254,3 +254,15 @@ struct Buffer *mutt_buffer_alloc(size_t size) return b; } + +/* Increases the allocated size of the buffer */ +void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size) +{ + if (new_size > buf->dsize) + { + size_t offset = buf->dptr - buf->data; + buf->dsize = new_size; + mutt_mem_realloc(&buf->data, buf->dsize); + buf->dptr = buf->data + offset; + } +} diff --git a/mutt/buffer.h b/mutt/buffer.h index e4b8ac9c6..330a56c27 100644 --- a/mutt/buffer.h +++ b/mutt/buffer.h @@ -46,6 +46,7 @@ size_t mutt_buffer_addstr(struct Buffer *buf, const char *s); struct Buffer *mutt_buffer_alloc(size_t size); void mutt_buffer_free(struct Buffer **p); struct Buffer *mutt_buffer_from(const char *seed); +void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size); struct Buffer *mutt_buffer_init(struct Buffer *b); bool mutt_buffer_is_empty(const struct Buffer *buf); struct Buffer *mutt_buffer_new(void);