Received: from [140.186.70.92] (port=49369 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PlGf7-0003ho-2F for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:05:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PlGf6-0001k9-4W for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:05:01 -0500 Received: from smtp5-g21.free.fr ([212.27.42.5]:51681) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PlGf5-0001js-Da for qemu-devel@nongnu.org; Fri, 04 Feb 2011 03:05:00 -0500 From: Corentin Chary Date: Fri, 4 Feb 2011 09:05:58 +0100 Message-Id: <1296806768-27787-7-git-send-email-corentincj@iksaif.net> In-Reply-To: <1296806768-27787-1-git-send-email-corentincj@iksaif.net> References: <1296806768-27787-1-git-send-email-corentincj@iksaif.net> Subject: [Qemu-devel] [PATCH v3 06/16] vnc: palette: use a pool to reduce memory allocations List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Corentin Chary , Andre Przywara , Qemu-development List , Alexander Graf We now that the palette will never have more than 256 elements. Let's use a pool to reduce malloc calls. Signed-off-by: Corentin Chary --- ui/vnc-palette.c | 18 ++---------------- ui/vnc-palette.h | 3 ++- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/ui/vnc-palette.c b/ui/vnc-palette.c index bff6445..c47420b 100644 --- a/ui/vnc-palette.c +++ b/ui/vnc-palette.c @@ -63,23 +63,9 @@ VncPalette *palette_new(size_t max, int bpp) void palette_destroy(VncPalette *palette) { - int i; - if (palette == NULL) { - return ; + qemu_free(palette); } - - for (i = 0; i < VNC_PALETTE_HASH_SIZE; i++) { - VncPaletteEntry *entry = QLIST_FIRST(&palette->table[i]); - while (entry) { - VncPaletteEntry *tmp = QLIST_NEXT(entry, next); - QLIST_REMOVE(entry, next); - qemu_free(entry); - entry = tmp; - } - } - - qemu_free(palette); } int palette_put(VncPalette *palette, uint32_t color) @@ -97,7 +83,7 @@ int palette_put(VncPalette *palette, uint32_t color) if (!entry) { VncPaletteEntry *entry; - entry = qemu_mallocz(sizeof(*entry)); + entry = &palette->pool[palette->size]; entry->color = color; entry->idx = idx; QLIST_INSERT_HEAD(&palette->table[hash], entry, next); diff --git a/ui/vnc-palette.h b/ui/vnc-palette.h index d0645eb..f57d0e7 100644 --- a/ui/vnc-palette.h +++ b/ui/vnc-palette.h @@ -34,6 +34,7 @@ #include #define VNC_PALETTE_HASH_SIZE 256 +#define VNC_PALETTE_MAX_SIZE 256 typedef struct VncPaletteEntry { int idx; @@ -42,7 +43,7 @@ typedef struct VncPaletteEntry { } VncPaletteEntry; typedef struct VncPalette { - QObject_HEAD; + VncPaletteEntry pool[VNC_PALETTE_MAX_SIZE]; size_t size; size_t max; int bpp; -- 1.7.3.4