From fd95243372f7657c2d24aed269e3be01bed1b87c Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Fri, 30 Oct 2015 12:10:12 +0100 Subject: buffer: factor out buffer_req_size Signed-off-by: Peter Lieven Signed-off-by: Gerd Hoffmann Reviewed-by: Daniel P. Berrange Message-id: 1446203414-4013-18-git-send-email-kraxel@redhat.com --- util/buffer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'util/buffer.c') diff --git a/util/buffer.c b/util/buffer.c index ae2907ebd4..31f1d9f286 100644 --- a/util/buffer.c +++ b/util/buffer.c @@ -24,6 +24,13 @@ #define BUFFER_MIN_INIT_SIZE 4096 #define BUFFER_MIN_SHRINK_SIZE 65536 +static size_t buffer_req_size(Buffer *buffer, size_t len) +{ + return MAX(BUFFER_MIN_INIT_SIZE, + pow2ceil(buffer->offset + len)); +} + + void buffer_init(Buffer *buffer, const char *name, ...) { va_list ap; @@ -61,8 +68,7 @@ void buffer_reserve(Buffer *buffer, size_t len) if ((buffer->capacity - buffer->offset) < len) { old = buffer->capacity; - buffer->capacity = pow2ceil(buffer->offset + len); - buffer->capacity = MAX(buffer->capacity, BUFFER_MIN_INIT_SIZE); + buffer->capacity = buffer_req_size(buffer, len); buffer->buffer = g_realloc(buffer->buffer, buffer->capacity); trace_buffer_resize(buffer->name ?: "unnamed", old, buffer->capacity); -- cgit v1.2.3