[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 1/4] vnc: make the Buffer capacity increase in power
From: |
Peter Lieven |
Subject: |
[Qemu-devel] [PATCH 1/4] vnc: make the Buffer capacity increase in powers of two |
Date: |
Thu, 27 Aug 2015 12:18:51 +0200 |
This makes sure the number of reallocs is in O(log N).
Signed-off-by: Peter Lieven <address@hidden>
---
ui/vnc.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/ui/vnc.c b/ui/vnc.c
index caf82f5..8cfd2d8 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -653,10 +653,13 @@ void vnc_framebuffer_update(VncState *vs, int x, int y,
int w, int h,
vnc_write_s32(vs, encoding);
}
+#define BUFFER_MIN_INIT_SIZE 4096
+
void buffer_reserve(Buffer *buffer, size_t len)
{
if ((buffer->capacity - buffer->offset) < len) {
- buffer->capacity += (len + 1024);
+ buffer->capacity = pow2ceil(buffer->capacity + len);
+ buffer->capacity = MAX(buffer->capacity, BUFFER_MIN_INIT_SIZE);
buffer->buffer = g_realloc(buffer->buffer, buffer->capacity);
}
}
--
1.9.1