From patchwork Thu Nov 11 16:56:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Chary X-Patchwork-Id: 70837 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by ozlabs.org (Postfix) with ESMTP id 3EA5CB7137 for ; Fri, 12 Nov 2010 04:14:02 +1100 (EST) Received: from localhost ([127.0.0.1]:48032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGadS-00058L-52 for incoming@patchwork.ozlabs.org; Thu, 11 Nov 2010 12:08:30 -0500 Received: from [140.186.70.92] (port=51958 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PGaSS-0008SZ-K4 for qemu-devel@nongnu.org; Thu, 11 Nov 2010 11:57:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PGaSP-0005W0-Nb for qemu-devel@nongnu.org; Thu, 11 Nov 2010 11:57:08 -0500 Received: from relay2-v.mail.gandi.net ([217.70.178.76]:57140) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PGaSP-0005Vk-F0 for qemu-devel@nongnu.org; Thu, 11 Nov 2010 11:57:05 -0500 X-Originating-IP: 217.70.178.36 Received: from mfilter2-v.gandi.net (mfilter2-v.gandi.net [217.70.178.36]) by relay2-v.mail.gandi.net (Postfix) with ESMTP id CB97E135E9; Thu, 11 Nov 2010 17:57:04 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter2-v.gandi.net Received: from relay2-v.mail.gandi.net ([217.70.178.76]) by mfilter2-v.gandi.net (mfilter2-v.gandi.net [217.70.178.36]) (amavisd-new, port 10024) with ESMTP id El766l0TI2Ad; Thu, 11 Nov 2010 17:57:04 +0100 (CET) X-Originating-IP: 82.241.209.44 Received: from localhost.localdomain (falgoret.iksaif.net [82.241.209.44]) (Authenticated sender: fake@iksaif.net) by relay2-v.mail.gandi.net (Postfix) with ESMTPSA id 42CF4135E5; Thu, 11 Nov 2010 17:57:03 +0100 (CET) From: Corentin Chary To: Qemu-development List Date: Thu, 11 Nov 2010 17:56:54 +0100 Message-Id: <1289494624-12807-6-git-send-email-corentincj@iksaif.net> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1289494624-12807-1-git-send-email-corentincj@iksaif.net> References: <1289494624-12807-1-git-send-email-corentincj@iksaif.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: Corentin Chary , Anthony Liguori , Alexander Graf , Andre Przywara Subject: [Qemu-devel] [PATCH v2 05/15] vnc: palette: use a pool to reduce memory allocations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;