]> granicus.if.org Git - libass/commitdiff
Append new cache items at the start of the collision list
author11rcombs <rodger.combs@gmail.com>
Fri, 24 Jan 2014 01:23:30 +0000 (02:23 +0100)
committerGrigori Goronzy <greg@chown.ath.cx>
Sat, 25 Jan 2014 01:22:47 +0000 (02:22 +0100)
The idea is that more recently-added cache items are more likely to
get hits.

Signed-off-by: wm4 <wm4@nowhere>
libass/ass_cache.c

index 91801a0abcc3759c80e521c49f068c6187a2c0c9..dd02e75026b605698dacc5623ce59cc20fe75201 100644 (file)
@@ -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)