From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4i-0002kn-83 for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TSq4c-0007KN-BZ for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TSq4c-0007KA-1j for qemu-devel@nongnu.org; Mon, 29 Oct 2012 10:12:14 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q9TECDPd031756 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 29 Oct 2012 10:12:13 -0400 From: Juan Quintela Date: Mon, 29 Oct 2012 15:11:37 +0100 Message-Id: <1351519903-26607-13-git-send-email-quintela@redhat.com> In-Reply-To: <1351519903-26607-1-git-send-email-quintela@redhat.com> References: <1351519903-26607-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 12/18] buffered_file: unfold buffered_append in buffered_put_buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: owasserm@redhat.com, mtosatti@redhat.com, avi@redhat.com, pbonzini@redhat.com It was the only user, and now buffered_put_buffer just do the append Signed-off-by: Juan Quintela --- buffered_file.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/buffered_file.c b/buffered_file.c index 2bdda27..017745d 100644 --- a/buffered_file.c +++ b/buffered_file.c @@ -42,22 +42,6 @@ typedef struct QEMUFileBuffered do { } while (0) #endif -static void buffered_append(QEMUFileBuffered *s, - const uint8_t *buf, size_t size) -{ - if (size > (s->buffer_capacity - s->buffer_size)) { - DPRINTF("increasing buffer capacity from %zu by %zu\n", - s->buffer_capacity, size + 1024); - - s->buffer_capacity += size + 1024; - - s->buffer = g_realloc(s->buffer, s->buffer_capacity); - } - - memcpy(s->buffer + s->buffer_size, buf, size); - s->buffer_size += size; -} - static ssize_t buffered_flush(QEMUFileBuffered *s) { size_t offset = 0; @@ -102,11 +86,22 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in return error; } - if (size > 0) { - DPRINTF("buffering %d bytes\n", size - offset); - buffered_append(s, buf, size); + if (size <= 0) { + return size; } + if (size > (s->buffer_capacity - s->buffer_size)) { + DPRINTF("increasing buffer capacity from %zu by %zu\n", + s->buffer_capacity, size + 1024); + + s->buffer_capacity += size + 1024; + + s->buffer = g_realloc(s->buffer, s->buffer_capacity); + } + + memcpy(s->buffer + s->buffer_size, buf, size); + s->buffer_size += size; + return size; } -- 1.7.11.7