summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-24 02:27:26 +0100
committerGrigori Goronzy <greg@chown.ath.cx>2014-01-25 02:22:48 +0100
commit65a934a254ed457920d8fb7e4cae9f6de8ee83d5 (patch)
tree36bf4a4457aa4c4ec67b315c11c3d6a2c2b237cb
parent7584bbd1cadead327e22a80264318462cd3bf149 (diff)
downloadlibass-65a934a254ed457920d8fb7e4cae9f6de8ee83d5.tar.bz2
libass-65a934a254ed457920d8fb7e4cae9f6de8ee83d5.tar.xz
Attempt to make code more readable
No more double pointer dereferencing.
-rw-r--r--libass/ass_cache.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c
index dd02e75..8234e5f 100644
--- a/libass/ass_cache.c
+++ b/libass/ass_cache.c
@@ -242,14 +242,16 @@ Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func,
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];
- 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;
+ CacheItem **bucketptr = &cache->map[bucket];
+
+ CacheItem *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 = *bucketptr;
+ *bucketptr = item;
cache->items++;
if (cache->size_func)
@@ -257,7 +259,7 @@ void *ass_cache_put(Cache *cache, void *key, void *value)
else
cache->cache_size++;
- return (*item)->value;
+ return item->value;
}
void *ass_cache_get(Cache *cache, void *key)