From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyNXH-0003Nm-01 for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZyNXE-0000S3-0x for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52947) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZyNXD-0000Rb-Ki for qemu-devel@nongnu.org; Mon, 16 Nov 2015 12:25:43 -0500 From: Gerd Hoffmann Date: Mon, 16 Nov 2015 18:25:31 +0100 Message-Id: <1447694735-3420-17-git-send-email-kraxel@redhat.com> In-Reply-To: <1447694735-3420-1-git-send-email-kraxel@redhat.com> References: <1447694735-3420-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 16/20] vnc: recycle empty vs->output buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Lieven , Gerd Hoffmann From: Peter Lieven If the vs->output buffer is empty it will be dropped by the next qio_buffer_move_empty in vnc_jobs_consume_buffer anyway. So reuse the allocated buffer from this buffer in the worker thread where we otherwise would start with an empty (unallocated buffer). Signed-off-by: Peter Lieven Reviewed-by: Daniel P. Berrange Message-id: 1446203414-4013-17-git-send-email-kraxel@redhat.com [ added a comment describing the non-obvious optimization ] Signed-off-by: Gerd Hoffmann --- ui/vnc-jobs.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ui/vnc-jobs.c b/ui/vnc-jobs.c index 12389cc..08f0163 100644 --- a/ui/vnc-jobs.c +++ b/ui/vnc-jobs.c @@ -235,6 +235,14 @@ static int vnc_worker_thread_loop(VncJobQueue *queue) vnc_unlock_output(job->vs); goto disconnected; } + if (buffer_empty(&job->vs->output)) { + /* + * Looks like a NOP as it obviously moves no data. But it + * moves the empty buffer, so we don't have to malloc a new + * one for vs.output + */ + buffer_move_empty(&vs.output, &job->vs->output); + } vnc_unlock_output(job->vs); /* Make a local copy of vs and switch output buffers */ -- 1.8.3.1