diff options
author | Peter Lieven <pl@kamp.de> | 2015-10-30 12:10:12 +0100 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2015-11-05 09:09:48 +0100 |
commit | fd95243372f7657c2d24aed269e3be01bed1b87c (patch) | |
tree | efc8645a3dea6cd868cbff2435e91bd21717a34d /util | |
parent | c3d6899c5e67dfd7ff195eccc10541f3b7e141a7 (diff) |
buffer: factor out buffer_req_size
Signed-off-by: Peter Lieven <pl@kamp.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Message-id: 1446203414-4013-18-git-send-email-kraxel@redhat.com
Diffstat (limited to 'util')
-rw-r--r-- | util/buffer.c | 10 |
1 files changed, 8 insertions, 2 deletions
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); |