[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/15] vnc: palette: use a pool to reduce memory all
From: |
Corentin Chary |
Subject: |
[Qemu-devel] [PATCH 05/15] vnc: palette: use a pool to reduce memory allocations |
Date: |
Wed, 11 Aug 2010 07:49:35 +0200 |
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 <address@hidden>
---
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 <stdint.h>
#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.1
- [Qemu-devel] [PATCH 00/15] vnc: adapative tight, zrle, zywrle, and bitmap module, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 01/15] vnc: don't set the quality if lossy encoding are disabled, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 02/15] vnc: add a way to get the update frequency for a given region, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 03/15] vnc: refresh lossy rect after a given timeout, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 04/15] vnc: tight: use the update frequency to choose between lossy and lossless, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 05/15] vnc: palette: use a pool to reduce memory allocations,
Corentin Chary <=
- [Qemu-devel] [PATCH 06/15] vnc: palette: add palette_init calls, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 07/15] vnc: palette: and fill and color calls., Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 09/15] vnc: fix uint8_t comparisons with negative values, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 08/15] vnc: Add ZRLE and ZYWRLE encodings., Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 10/15] vnc: fix lossy rect refreshing, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 11/15] bitmap: add a generic bitmap and bitops library, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 12/15] vnc: use the new generic bitmap functions, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 13/15] vnc: don't try to send bigger updates that client height, Corentin Chary, 2010/08/11
- [Qemu-devel] [PATCH 14/15] vnc: tight: tweak adaptive tight settings, Corentin Chary, 2010/08/11