gmime r1434 - in trunk: . util
- From: fejj svn gnome org
- To: svn-commits-list gnome org
- Subject: gmime r1434 - in trunk: . util
- Date: Sun, 7 Sep 2008 16:54:50 +0000 (UTC)
Author: fejj
Date: Sun Sep 7 16:54:50 2008
New Revision: 1434
URL: http://svn.gnome.org/viewvc/gmime?rev=1434&view=rev
Log:
2008-09-07 Jeffrey Stedfast <fejj novell com>
* util/cache.c: Updated to use GSlice instead of a custom MemChunk
allocator.
Modified:
trunk/ChangeLog
trunk/util/cache.c
trunk/util/cache.h
Modified: trunk/util/cache.c
==============================================================================
--- trunk/util/cache.c (original)
+++ trunk/util/cache.c Sun Sep 7 16:54:50 2008
@@ -26,6 +26,19 @@
#include "cache.h"
+static void
+cache_node_free (gpointer node_data)
+{
+ CacheNode *node = (CacheNode *) node_data;
+ Cache *cache = node->cache;
+
+ cache->free_node (node);
+ g_free (node->key);
+
+ g_slice_free1 (cache->node_size, node);
+}
+
+
Cache *
cache_new (CacheNodeExpireFunc expire, CacheNodeFreeFunc free_node, size_t node_size, size_t max_size)
{
@@ -35,8 +48,8 @@
list_init (&cache->list);
cache->expire = expire;
cache->free_node = free_node;
- cache->node_hash = g_hash_table_new (g_str_hash, g_str_equal);
- cache->node_chunks = memchunk_new (node_size, max_size, FALSE);
+ cache->node_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, cache_node_free);
+ cache->node_size = node_size;
cache->max_size = max_size;
cache->size = 0;
@@ -44,31 +57,10 @@
}
-static void
-cache_node_free (CacheNode *node)
-{
- Cache *cache;
-
- cache = node->cache;
-
- cache->free_node (node);
- g_free (node->key);
- memchunk_free (cache->node_chunks, node);
-}
-
-
-static void
-cache_node_foreach_cb (gpointer key, gpointer value, gpointer user_data)
-{
- cache_node_free ((CacheNode *) value);
-}
-
void
cache_free (Cache *cache)
{
- g_hash_table_foreach (cache->node_hash, cache_node_foreach_cb, NULL);
g_hash_table_destroy (cache->node_hash);
- memchunk_destroy (cache->node_chunks);
g_free (cache);
}
@@ -82,9 +74,8 @@
while (node->prev && cache->size > cache->max_size) {
prev = node->prev;
if (cache->expire (cache, (CacheNode *) node)) {
- g_hash_table_remove (cache->node_hash, ((CacheNode *) node)->key);
list_unlink (node);
- cache_node_free ((CacheNode *) node);
+ g_hash_table_remove (cache->node_hash, ((CacheNode *) node)->key);
cache->size--;
}
node = prev;
@@ -101,7 +92,7 @@
if (cache->size > cache->max_size)
cache_expire_unused (cache);
- node = memchunk_alloc (cache->node_chunks);
+ node = g_slice_alloc (cache->node_size);
node->key = g_strdup (key);
node->cache = cache;
@@ -131,8 +122,7 @@
Cache *cache;
cache = node->cache;
- g_hash_table_remove (cache->node_hash, node->key);
list_unlink ((ListNode *) node);
- cache_node_free (node);
+ g_hash_table_remove (cache->node_hash, node->key);
cache->size--;
}
Modified: trunk/util/cache.h
==============================================================================
--- trunk/util/cache.h (original)
+++ trunk/util/cache.h Sun Sep 7 16:54:50 2008
@@ -27,7 +27,6 @@
#include <sys/types.h>
#include <util/list.h>
-#include <util/memchunk.h>
G_BEGIN_DECLS
@@ -46,7 +45,7 @@
List list;
size_t size;
size_t max_size;
- MemChunk *node_chunks;
+ size_t node_size;
GHashTable *node_hash;
CacheNodeExpireFunc expire;
CacheNodeFreeFunc free_node;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]