diff options
Diffstat (limited to 'libass/ass_cache.c')
-rw-r--r-- | libass/ass_cache.c | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/libass/ass_cache.c b/libass/ass_cache.c index 524a1c8..ac0a00f 100644 --- a/libass/ass_cache.c +++ b/libass/ass_cache.c @@ -51,13 +51,13 @@ static void hashmap_item_dtor(void *key, size_t key_size, void *value, free(value); } -hashmap_t *hashmap_init(ass_library_t *library, size_t key_size, - size_t value_size, int nbuckets, - hashmap_item_dtor_t item_dtor, - hashmap_key_compare_t key_compare, - hashmap_hash_t hash) +Hashmap *hashmap_init(ASS_Library *library, size_t key_size, + size_t value_size, int nbuckets, + HashmapItemDtor item_dtor, + HashmapKeyCompare key_compare, + HashmapHash hash) { - hashmap_t *map = calloc(1, sizeof(hashmap_t)); + Hashmap *map = calloc(1, sizeof(Hashmap)); map->library = library; map->nbuckets = nbuckets; map->key_size = key_size; @@ -69,7 +69,7 @@ hashmap_t *hashmap_init(ass_library_t *library, size_t key_size, return map; } -void hashmap_done(hashmap_t *map) +void hashmap_done(Hashmap *map) { int i; // print stats @@ -81,9 +81,9 @@ void hashmap_done(hashmap_t *map) map->miss_count, map->count); for (i = 0; i < map->nbuckets; ++i) { - hashmap_item_t *item = map->root[i]; + HashmapItem *item = map->root[i]; while (item) { - hashmap_item_t *next = item->next; + HashmapItem *next = item->next; map->item_dtor(item->key, map->key_size, item->value, map->value_size); free(item); @@ -95,17 +95,17 @@ void hashmap_done(hashmap_t *map) } // does nothing if key already exists -void *hashmap_insert(hashmap_t *map, void *key, void *value) +void *hashmap_insert(Hashmap *map, void *key, void *value) { unsigned hash = map->hash(key, map->key_size); - hashmap_item_t **next = map->root + (hash % map->nbuckets); + HashmapItem **next = map->root + (hash % map->nbuckets); while (*next) { if (map->key_compare(key, (*next)->key, map->key_size)) return (*next)->value; next = &((*next)->next); assert(next); } - (*next) = malloc(sizeof(hashmap_item_t)); + (*next) = malloc(sizeof(HashmapItem)); (*next)->key = malloc(map->key_size); (*next)->value = malloc(map->value_size); memcpy((*next)->key, key, map->key_size); @@ -116,10 +116,10 @@ void *hashmap_insert(hashmap_t *map, void *key, void *value) return (*next)->value; } -void *hashmap_find(hashmap_t *map, void *key) +void *hashmap_find(Hashmap *map, void *key) { unsigned hash = map->hash(key, map->key_size); - hashmap_item_t *item = map->root[hash % map->nbuckets]; + HashmapItem *item = map->root[hash % map->nbuckets]; while (item) { if (map->key_compare(key, item->key, map->key_size)) { map->hit_count++; @@ -136,7 +136,7 @@ void *hashmap_find(hashmap_t *map, void *key) static unsigned font_desc_hash(void *buf, size_t len) { - ass_font_desc_t *desc = buf; + ASS_FontDesc *desc = buf; unsigned hval; hval = fnv_32a_str(desc->family, FNV1_32A_INIT); hval = fnv_32a_buf(&desc->bold, sizeof(desc->bold), hval); @@ -146,8 +146,8 @@ static unsigned font_desc_hash(void *buf, size_t len) static int font_compare(void *key1, void *key2, size_t key_size) { - ass_font_desc_t *a = key1; - ass_font_desc_t *b = key2; + ASS_FontDesc *a = key1; + ASS_FontDesc *b = key2; if (strcmp(a->family, b->family) != 0) return 0; if (a->bold != b->bold) @@ -166,8 +166,8 @@ static void font_hash_dtor(void *key, size_t key_size, void *value, free(key); } -ass_font_t *ass_font_cache_find(hashmap_t *font_cache, - ass_font_desc_t *desc) +ASS_Font *ass_font_cache_find(Hashmap *font_cache, + ASS_FontDesc *desc) { return hashmap_find(font_cache, desc); } @@ -176,22 +176,22 @@ ass_font_t *ass_font_cache_find(hashmap_t *font_cache, * \brief Add a face struct to cache. * \param font font struct */ -void *ass_font_cache_add(hashmap_t *font_cache, ass_font_t *font) +void *ass_font_cache_add(Hashmap *font_cache, ASS_Font *font) { return hashmap_insert(font_cache, &(font->desc), font); } -hashmap_t *ass_font_cache_init(ass_library_t *library) +Hashmap *ass_font_cache_init(ASS_Library *library) { - hashmap_t *font_cache; - font_cache = hashmap_init(library, sizeof(ass_font_desc_t), - sizeof(ass_font_t), + Hashmap *font_cache; + font_cache = hashmap_init(library, sizeof(ASS_FontDesc), + sizeof(ASS_Font), 1000, font_hash_dtor, font_compare, font_desc_hash); return font_cache; } -void ass_font_cache_done(hashmap_t *font_cache) +void ass_font_cache_done(Hashmap *font_cache) { hashmap_done(font_cache); } @@ -209,7 +209,7 @@ void ass_font_cache_done(hashmap_t *font_cache) static void bitmap_hash_dtor(void *key, size_t key_size, void *value, size_t value_size) { - bitmap_hash_val_t *v = value; + BitmapHashValue *v = value; if (v->bm) ass_free_bitmap(v->bm); if (v->bm_o) @@ -220,8 +220,8 @@ static void bitmap_hash_dtor(void *key, size_t key_size, void *value, free(value); } -void *cache_add_bitmap(hashmap_t *bitmap_cache, bitmap_hash_key_t *key, - bitmap_hash_val_t *val) +void *cache_add_bitmap(Hashmap *bitmap_cache, BitmapHashKey *key, + BitmapHashValue *val) { // Note: this is only an approximation if (val->bm_o) @@ -237,32 +237,32 @@ void *cache_add_bitmap(hashmap_t *bitmap_cache, bitmap_hash_key_t *key, * \param key hash key * \return requested hash val or 0 if not found */ -bitmap_hash_val_t *cache_find_bitmap(hashmap_t *bitmap_cache, - bitmap_hash_key_t *key) +BitmapHashValue *cache_find_bitmap(Hashmap *bitmap_cache, + BitmapHashKey *key) { return hashmap_find(bitmap_cache, key); } -hashmap_t *ass_bitmap_cache_init(ass_library_t *library) +Hashmap *ass_bitmap_cache_init(ASS_Library *library) { - hashmap_t *bitmap_cache; + Hashmap *bitmap_cache; bitmap_cache = hashmap_init(library, - sizeof(bitmap_hash_key_t), - sizeof(bitmap_hash_val_t), + sizeof(BitmapHashKey), + sizeof(BitmapHashValue), 0xFFFF + 13, bitmap_hash_dtor, bitmap_compare, bitmap_hash); return bitmap_cache; } -void ass_bitmap_cache_done(hashmap_t *bitmap_cache) +void ass_bitmap_cache_done(Hashmap *bitmap_cache) { hashmap_done(bitmap_cache); } -hashmap_t *ass_bitmap_cache_reset(hashmap_t *bitmap_cache) +Hashmap *ass_bitmap_cache_reset(Hashmap *bitmap_cache) { - ass_library_t *lib = bitmap_cache->library; + ASS_Library *lib = bitmap_cache->library; ass_bitmap_cache_done(bitmap_cache); return ass_bitmap_cache_init(lib); @@ -274,7 +274,7 @@ hashmap_t *ass_bitmap_cache_reset(hashmap_t *bitmap_cache) static void glyph_hash_dtor(void *key, size_t key_size, void *value, size_t value_size) { - glyph_hash_val_t *v = value; + GlyphHashValue *v = value; if (v->glyph) FT_Done_Glyph(v->glyph); if (v->outline_glyph) @@ -283,8 +283,8 @@ static void glyph_hash_dtor(void *key, size_t key_size, void *value, free(value); } -void *cache_add_glyph(hashmap_t *glyph_cache, glyph_hash_key_t *key, - glyph_hash_val_t *val) +void *cache_add_glyph(Hashmap *glyph_cache, GlyphHashKey *key, + GlyphHashValue *val) { return hashmap_insert(glyph_cache, key, val); } @@ -294,30 +294,30 @@ void *cache_add_glyph(hashmap_t *glyph_cache, glyph_hash_key_t *key, * \param key hash key * \return requested hash val or 0 if not found */ -glyph_hash_val_t *cache_find_glyph(hashmap_t *glyph_cache, - glyph_hash_key_t *key) +GlyphHashValue *cache_find_glyph(Hashmap *glyph_cache, + GlyphHashKey *key) { return hashmap_find(glyph_cache, key); } -hashmap_t *ass_glyph_cache_init(ass_library_t *library) +Hashmap *ass_glyph_cache_init(ASS_Library *library) { - hashmap_t *glyph_cache; - glyph_cache = hashmap_init(library, sizeof(glyph_hash_key_t), - sizeof(glyph_hash_val_t), + Hashmap *glyph_cache; + glyph_cache = hashmap_init(library, sizeof(GlyphHashKey), + sizeof(GlyphHashValue), 0xFFFF + 13, glyph_hash_dtor, glyph_compare, glyph_hash); return glyph_cache; } -void ass_glyph_cache_done(hashmap_t *glyph_cache) +void ass_glyph_cache_done(Hashmap *glyph_cache) { hashmap_done(glyph_cache); } -hashmap_t *ass_glyph_cache_reset(hashmap_t *glyph_cache) +Hashmap *ass_glyph_cache_reset(Hashmap *glyph_cache) { - ass_library_t *lib = glyph_cache->library; + ASS_Library *lib = glyph_cache->library; ass_glyph_cache_done(glyph_cache); return ass_glyph_cache_init(lib); @@ -330,16 +330,16 @@ hashmap_t *ass_glyph_cache_reset(hashmap_t *glyph_cache) static void composite_hash_dtor(void *key, size_t key_size, void *value, size_t value_size) { - composite_hash_val_t *v = value; + CompositeHashValue *v = value; free(v->a); free(v->b); free(key); free(value); } -void *cache_add_composite(hashmap_t *composite_cache, - composite_hash_key_t *key, - composite_hash_val_t *val) +void *cache_add_composite(Hashmap *composite_cache, + CompositeHashKey *key, + CompositeHashValue *val) { return hashmap_insert(composite_cache, key, val); } @@ -349,31 +349,31 @@ void *cache_add_composite(hashmap_t *composite_cache, * \param key hash key * \return requested hash val or 0 if not found */ -composite_hash_val_t *cache_find_composite(hashmap_t *composite_cache, - composite_hash_key_t *key) +CompositeHashValue *cache_find_composite(Hashmap *composite_cache, + CompositeHashKey *key) { return hashmap_find(composite_cache, key); } -hashmap_t *ass_composite_cache_init(ass_library_t *library) +Hashmap *ass_composite_cache_init(ASS_Library *library) { - hashmap_t *composite_cache; - composite_cache = hashmap_init(library, sizeof(composite_hash_key_t), - sizeof(composite_hash_val_t), + Hashmap *composite_cache; + composite_cache = hashmap_init(library, sizeof(CompositeHashKey), + sizeof(CompositeHashValue), 0xFFFF + 13, composite_hash_dtor, composite_compare, composite_hash); return composite_cache; } -void ass_composite_cache_done(hashmap_t *composite_cache) +void ass_composite_cache_done(Hashmap *composite_cache) { hashmap_done(composite_cache); } -hashmap_t *ass_composite_cache_reset(hashmap_t *composite_cache) +Hashmap *ass_composite_cache_reset(Hashmap *composite_cache) { - ass_library_t *lib = composite_cache->library; + ASS_Library *lib = composite_cache->library; ass_composite_cache_done(composite_cache); return ass_composite_cache_init(lib); |