From patchwork Wed Aug 11 05:49:35 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin Chary X-Patchwork-Id: 61443 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 53852B70AF for ; Wed, 11 Aug 2010 15:58:12 +1000 (EST) Received: from localhost ([127.0.0.1]:50918 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4KA-0000nF-Tl for incoming@patchwork.ozlabs.org; Wed, 11 Aug 2010 01:58:02 -0400 Received: from [140.186.70.92] (port=37860 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oj4Cp-0005pc-Ik for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oj4Cn-0007Qk-F4 for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:27 -0400 Received: from relay1-v.mail.gandi.net ([217.70.178.75]:45841 helo=mrelay1-v.mgt.gandi.net) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oj4Cn-0007QS-5p for qemu-devel@nongnu.org; Wed, 11 Aug 2010 01:50:25 -0400 X-Originating-IP: 217.70.178.37 Received: from mfilter3-v.gandi.net (mfilter3-v.gandi.net [217.70.178.37]) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTP id B0803362BF; Wed, 11 Aug 2010 07:50:24 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter3-v.gandi.net Received: from mrelay1-v.mgt.gandi.net ([217.70.178.75]) by mfilter3-v.gandi.net (mfilter3-v.gandi.net [217.70.178.37]) (amavisd-new, port 10024) with ESMTP id 4IgJm73z0dO0; Wed, 11 Aug 2010 07:50:24 +0200 (CEST) X-Originating-IP: 82.241.209.44 Received: from tartiflon (falgoret.iksaif.net [82.241.209.44]) (Authenticated sender: fake@iksaif.net) by mrelay1-v.mgt.gandi.net (Postfix) with ESMTPSA id EB84B362C2; Wed, 11 Aug 2010 07:50:19 +0200 (CEST) From: Corentin Chary To: Qemu-development List Date: Wed, 11 Aug 2010 07:49:35 +0200 Message-Id: <1281505785-22523-6-git-send-email-corentincj@iksaif.net> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1281505785-22523-1-git-send-email-corentincj@iksaif.net> References: <1281505785-22523-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 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;