From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXRm4-0007uP-C4 for qemu-devel@nongnu.org; Thu, 03 Sep 2015 06:29:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZXRm1-0004TI-80 for qemu-devel@nongnu.org; Thu, 03 Sep 2015 06:29:44 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:57521 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZXRm0-0004Sw-Tb for qemu-devel@nongnu.org; Thu, 03 Sep 2015 06:29:41 -0400 References: <1440670734-5616-1-git-send-email-pl@kamp.de> <1440670734-5616-2-git-send-email-pl@kamp.de> <1441270602.557.12.camel@redhat.com> From: Peter Lieven Message-ID: <55E82110.2070504@kamp.de> Date: Thu, 3 Sep 2015 12:29:36 +0200 MIME-Version: 1.0 In-Reply-To: <1441270602.557.12.camel@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 1/4] vnc: make the Buffer capacity increase in powers of two List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org 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: 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); } BR, Peter