summaryrefslogtreecommitdiff
path: root/navit/cache.c
diff options
context:
space:
mode:
authorrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-08-17 19:45:11 +0000
committerrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-08-17 19:45:11 +0000
commitaf8ad4c372cef2ebbb7e77597e85df1a63cc47cb (patch)
tree7789367a5db07001e208c08e4d434a951d1afafa /navit/cache.c
parent1a72c3b03b88bf74ce0f9231776e3983b3ec6acb (diff)
downloadnavit-svn-af8ad4c372cef2ebbb7e77597e85df1a63cc47cb.tar.gz
Fix:core:Use slices for cache.c memory allocations.
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3532 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/cache.c')
-rw-r--r--navit/cache.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/navit/cache.c b/navit/cache.c
index 50a1ad9a..b4aa9e0a 100644
--- a/navit/cache.c
+++ b/navit/cache.c
@@ -148,7 +148,7 @@ cache_remove(struct cache *cache, struct cache_entry *entry)
{
dbg(1,"remove 0x%x 0x%x 0x%x 0x%x 0x%x\n", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
g_hash_table_remove(cache->hash, (gpointer)(entry->id));
- g_free(entry);
+ g_slice_free1(entry->size, entry);
}
static struct cache_entry *
@@ -193,7 +193,7 @@ cache_entry_new(struct cache *cache, void *id, int size)
{
size+=cache->entry_size;
cache->misses+=size;
- struct cache_entry *ret=(struct cache_entry *)g_malloc0(size);
+ struct cache_entry *ret=(struct cache_entry *)g_slice_alloc0(size);
ret->size=size;
ret->usage=1;
memcpy(ret->id, id, cache->id_size*sizeof(int));
@@ -212,7 +212,21 @@ static struct cache_entry *
cache_trim(struct cache *cache, struct cache_entry *entry)
{
dbg(1,"trim 0x%x 0x%x 0x%x 0x%x 0x%x\n", entry->id[0], entry->id[1], entry->id[2], entry->id[3], entry->id[4]);
- return g_realloc(entry, cache->entry_size);
+ dbg(0,"Trim %x from %d -> %d\n", entry->id[0], entry->size, cache->size);
+ struct cache_entry *new_entry;
+ if ( cache->entry_size < entry->size )
+ {
+ new_entry = g_slice_alloc0(cache->entry_size);
+ memcpy(new_entry, entry, cache->entry_size);
+ g_slice_free1( entry->size, entry);
+ new_entry->size = cache->entry_size;
+ }
+ else
+ {
+ new_entry = entry;
+ }
+
+ return new_entry;
}
static struct cache_entry *