]> granicus.if.org Git - neomutt/commitdiff
Create mutt_buffer_increase_size() function
authorKevin McCarthy <kevin@8t8.us>
Sat, 26 May 2018 21:46:16 +0000 (14:46 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Sep 2018 17:06:08 +0000 (18:06 +0100)
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.

mutt/buffer.c
mutt/buffer.h

index b47bb8abf369bfc4a8c7af9f2e1edeef741fafc4..3cb89c21000a6a9436adf2d92693c181e773f629 100644 (file)
@@ -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;
+  }
+}
index e4b8ac9c6dc9b99ea6ebe1231d920aca13ea02c6..330a56c27c05d20584acc1fe0141f5c6660a2b94 100644 (file)
@@ -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);