diff mbox

[1/4] vnc: make the Buffer capacity increase in powers of two

Message ID 55E82110.2070504@kamp.de
State New
Headers show

Commit Message

Peter Lieven Sept. 3, 2015, 10:29 a.m. UTC
Am 03.09.2015 um 10:56 schrieb Gerd Hoffmann:
> On Do, 2015-08-27 at 12:18 +0200, Peter Lieven wrote:
>> This makes sure the number of reallocs is in O(log N).
> Looks good, applied.
>

I think there is a small error. The new capacity should be calculated as follows:



BR,
Peter

Comments

Gerd Hoffmann Sept. 3, 2015, 10:47 a.m. UTC | #1
On Do, 2015-09-03 at 12:29 +0200, Peter Lieven wrote:
> -        buffer->capacity = pow2ceil(buffer->capacity + len);
> +        buffer->capacity = pow2ceil(buffer->offset + len);

Updated patch.

thanks,
  Gerd
diff mbox

Patch

diff --git a/ui/vnc.c b/ui/vnc.c
index 8cfd2d8..79d3ff3 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -658,7 +658,7 @@  void vnc_framebuffer_update(VncState *vs, int x, int y, int w, int h,
  void buffer_reserve(Buffer *buffer, size_t len)
  {
      if ((buffer->capacity - buffer->offset) < len) {
-        buffer->capacity = pow2ceil(buffer->capacity + len);
+        buffer->capacity = pow2ceil(buffer->offset + len);
          buffer->capacity = MAX(buffer->capacity, BUFFER_MIN_INIT_SIZE);
          buffer->buffer = g_realloc(buffer->buffer, buffer->capacity);
      }