summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
author11rcombs <rodger.combs@gmail.com>2014-01-24 02:23:30 +0100
committerGrigori Goronzy <greg@chown.ath.cx>2014-01-25 02:22:47 +0100
commit7584bbd1cadead327e22a80264318462cd3bf149 (patch)
tree412ca39bd0d2e20e87b7ba21a653fc892d720ad6
parent975d277b37e3bb8fb3d56ca20a906f4171703d00 (diff)
downloadlibass-7584bbd1cadead327e22a80264318462cd3bf149.tar.bz2
libass-7584bbd1cadead327e22a80264318462cd3bf149.tar.xz
Append new cache items at the start of the collision list
The idea is that more recently-added cache items are more likely to get hits. Signed-off-by: wm4 <wm4@nowhere>
-rw-r--r--libass/ass_cache.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c
index 91801a0..dd02e75 100644
--- a/libass/ass_cache.c
+++ b/libass/ass_cache.c
@@ -243,13 +243,13 @@ void *ass_cache_put(Cache *cache, void *key, void *value)
{
unsigned bucket = cache->hash_func(key, cache->key_size) % cache->buckets;
CacheItem **item = &cache->map[bucket];
- while (*item)
- item = &(*item)->next;
+ CacheItem *next = *item;
(*item) = calloc(1, sizeof(CacheItem));
(*item)->key = malloc(cache->key_size);
(*item)->value = malloc(cache->value_size);
memcpy((*item)->key, key, cache->key_size);
memcpy((*item)->value, value, cache->value_size);
+ (*item)->next = next;
cache->items++;
if (cache->size_func)