2007-04-09 04:02:40 +02:00
|
|
|
/*
|
2008-12-28 09:09:59 +01:00
|
|
|
* Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of libass.
|
|
|
|
*
|
2010-11-11 05:48:08 +01:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
2008-12-28 09:09:59 +01:00
|
|
|
*
|
2010-11-11 05:48:08 +01:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2008-12-28 09:09:59 +01:00
|
|
|
*/
|
2007-04-09 04:02:40 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_GLYPH_H
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
#include "ass_utils.h"
|
2007-04-09 04:02:40 +02:00
|
|
|
#include "ass.h"
|
|
|
|
#include "ass_fontconfig.h"
|
|
|
|
#include "ass_font.h"
|
|
|
|
#include "ass_bitmap.h"
|
|
|
|
#include "ass_cache.h"
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static unsigned hashmap_hash(void *buf, size_t len)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return fnv_32a_buf(buf, len, FNV1_32A_INIT);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static int hashmap_key_compare(void *a, void *b, size_t size)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return memcmp(a, b, size) == 0;
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static void hashmap_item_dtor(void *key, size_t key_size, void *value,
|
|
|
|
size_t value_size)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
free(key);
|
|
|
|
free(value);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *hashmap_init(ASS_Library *library, size_t key_size,
|
|
|
|
size_t value_size, int nbuckets,
|
|
|
|
HashmapItemDtor item_dtor,
|
|
|
|
HashmapKeyCompare key_compare,
|
|
|
|
HashmapHash hash)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *map = calloc(1, sizeof(Hashmap));
|
2009-07-14 00:43:25 +02:00
|
|
|
map->library = library;
|
2009-07-11 17:48:50 +02:00
|
|
|
map->nbuckets = nbuckets;
|
|
|
|
map->key_size = key_size;
|
|
|
|
map->value_size = value_size;
|
|
|
|
map->root = calloc(nbuckets, sizeof(hashmap_item_p));
|
|
|
|
map->item_dtor = item_dtor ? item_dtor : hashmap_item_dtor;
|
|
|
|
map->key_compare = key_compare ? key_compare : hashmap_key_compare;
|
|
|
|
map->hash = hash ? hash : hashmap_hash;
|
|
|
|
return map;
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void hashmap_done(Hashmap *map)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
int i;
|
|
|
|
// print stats
|
|
|
|
if (map->count > 0 || map->hit_count + map->miss_count > 0)
|
2009-07-14 00:43:25 +02:00
|
|
|
ass_msg(map->library, MSGL_V,
|
|
|
|
"cache statistics: \n total accesses: %d\n hits: %d\n "
|
|
|
|
"misses: %d\n object count: %d",
|
2009-07-11 17:48:50 +02:00
|
|
|
map->hit_count + map->miss_count, map->hit_count,
|
|
|
|
map->miss_count, map->count);
|
2008-01-17 17:50:19 +01:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
for (i = 0; i < map->nbuckets; ++i) {
|
2009-09-02 03:23:51 +02:00
|
|
|
HashmapItem *item = map->root[i];
|
2009-07-11 17:48:50 +02:00
|
|
|
while (item) {
|
2009-09-02 03:23:51 +02:00
|
|
|
HashmapItem *next = item->next;
|
2009-07-11 17:48:50 +02:00
|
|
|
map->item_dtor(item->key, map->key_size, item->value,
|
|
|
|
map->value_size);
|
|
|
|
free(item);
|
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(map->root);
|
|
|
|
free(map);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// does nothing if key already exists
|
2009-09-02 03:23:51 +02:00
|
|
|
void *hashmap_insert(Hashmap *map, void *key, void *value)
|
2009-07-11 17:48:50 +02:00
|
|
|
{
|
|
|
|
unsigned hash = map->hash(key, map->key_size);
|
2009-09-02 03:23:51 +02:00
|
|
|
HashmapItem **next = map->root + (hash % map->nbuckets);
|
2009-07-11 17:48:50 +02:00
|
|
|
while (*next) {
|
|
|
|
if (map->key_compare(key, (*next)->key, map->key_size))
|
|
|
|
return (*next)->value;
|
|
|
|
next = &((*next)->next);
|
|
|
|
assert(next);
|
|
|
|
}
|
2009-09-02 03:23:51 +02:00
|
|
|
(*next) = malloc(sizeof(HashmapItem));
|
2009-07-11 17:48:50 +02:00
|
|
|
(*next)->key = malloc(map->key_size);
|
|
|
|
(*next)->value = malloc(map->value_size);
|
|
|
|
memcpy((*next)->key, key, map->key_size);
|
|
|
|
memcpy((*next)->value, value, map->value_size);
|
|
|
|
(*next)->next = 0;
|
|
|
|
|
|
|
|
map->count++;
|
|
|
|
return (*next)->value;
|
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void *hashmap_find(Hashmap *map, void *key)
|
2009-07-11 17:48:50 +02:00
|
|
|
{
|
|
|
|
unsigned hash = map->hash(key, map->key_size);
|
2009-09-02 03:23:51 +02:00
|
|
|
HashmapItem *item = map->root[hash % map->nbuckets];
|
2009-07-11 17:48:50 +02:00
|
|
|
while (item) {
|
|
|
|
if (map->key_compare(key, item->key, map->key_size)) {
|
|
|
|
map->hit_count++;
|
|
|
|
return item->value;
|
|
|
|
}
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
map->miss_count++;
|
|
|
|
return 0;
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------
|
|
|
|
// font cache
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static unsigned font_desc_hash(void *buf, size_t len)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_FontDesc *desc = buf;
|
2009-07-11 17:48:50 +02:00
|
|
|
unsigned hval;
|
|
|
|
hval = fnv_32a_str(desc->family, FNV1_32A_INIT);
|
|
|
|
hval = fnv_32a_buf(&desc->bold, sizeof(desc->bold), hval);
|
|
|
|
hval = fnv_32a_buf(&desc->italic, sizeof(desc->italic), hval);
|
|
|
|
return hval;
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static int font_compare(void *key1, void *key2, size_t key_size)
|
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_FontDesc *a = key1;
|
|
|
|
ASS_FontDesc *b = key2;
|
2009-07-11 17:48:50 +02:00
|
|
|
if (strcmp(a->family, b->family) != 0)
|
|
|
|
return 0;
|
|
|
|
if (a->bold != b->bold)
|
|
|
|
return 0;
|
|
|
|
if (a->italic != b->italic)
|
|
|
|
return 0;
|
|
|
|
if (a->treat_family_as_pattern != b->treat_family_as_pattern)
|
|
|
|
return 0;
|
2010-11-11 05:48:08 +01:00
|
|
|
if (a->vertical != b->vertical)
|
|
|
|
return 0;
|
2009-07-11 17:48:50 +02:00
|
|
|
return 1;
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static void font_hash_dtor(void *key, size_t key_size, void *value,
|
|
|
|
size_t value_size)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
ass_font_free(value);
|
|
|
|
free(key);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_Font *ass_font_cache_find(Hashmap *font_cache,
|
|
|
|
ASS_FontDesc *desc)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_find(font_cache, desc);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Add a face struct to cache.
|
|
|
|
* \param font font struct
|
|
|
|
*/
|
2009-09-02 03:23:51 +02:00
|
|
|
void *ass_font_cache_add(Hashmap *font_cache, ASS_Font *font)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_insert(font_cache, &(font->desc), font);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_font_cache_init(ASS_Library *library)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *font_cache;
|
|
|
|
font_cache = hashmap_init(library, sizeof(ASS_FontDesc),
|
|
|
|
sizeof(ASS_Font),
|
2009-07-11 17:48:50 +02:00
|
|
|
1000,
|
|
|
|
font_hash_dtor, font_compare, font_desc_hash);
|
|
|
|
return font_cache;
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void ass_font_cache_done(Hashmap *font_cache)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
hashmap_done(font_cache);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-05-04 08:48:21 +02:00
|
|
|
|
|
|
|
// Create hash/compare functions for bitmap and glyph
|
|
|
|
#define CREATE_HASH_FUNCTIONS
|
2009-07-14 00:43:25 +02:00
|
|
|
#include "ass_cache_template.h"
|
2009-05-04 08:48:21 +02:00
|
|
|
#define CREATE_COMPARISON_FUNCTIONS
|
2009-07-14 00:43:25 +02:00
|
|
|
#include "ass_cache_template.h"
|
2009-05-04 08:48:21 +02:00
|
|
|
|
2007-04-09 04:02:40 +02:00
|
|
|
//---------------------------------
|
2008-01-17 17:50:19 +01:00
|
|
|
// bitmap cache
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static void bitmap_hash_dtor(void *key, size_t key_size, void *value,
|
|
|
|
size_t value_size)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
BitmapHashValue *v = value;
|
2009-07-11 17:48:50 +02:00
|
|
|
if (v->bm)
|
|
|
|
ass_free_bitmap(v->bm);
|
|
|
|
if (v->bm_o)
|
|
|
|
ass_free_bitmap(v->bm_o);
|
|
|
|
if (v->bm_s)
|
|
|
|
ass_free_bitmap(v->bm_s);
|
|
|
|
free(key);
|
|
|
|
free(value);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void *cache_add_bitmap(Hashmap *bitmap_cache, BitmapHashKey *key,
|
|
|
|
BitmapHashValue *val)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-19 21:33:29 +02:00
|
|
|
// Note: this is only an approximation
|
|
|
|
if (val->bm_o)
|
|
|
|
bitmap_cache->cache_size += val->bm_o->w * val->bm_o->h * 3;
|
2009-09-02 03:23:51 +02:00
|
|
|
else if (val->bm)
|
2009-07-19 21:33:29 +02:00
|
|
|
bitmap_cache->cache_size += val->bm->w * val->bm->h * 3;
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_insert(bitmap_cache, key, val);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2008-01-17 17:50:19 +01:00
|
|
|
* \brief Get a bitmap from bitmap cache.
|
2007-04-09 04:02:40 +02:00
|
|
|
* \param key hash key
|
2008-01-17 17:50:19 +01:00
|
|
|
* \return requested hash val or 0 if not found
|
2009-07-11 17:48:50 +02:00
|
|
|
*/
|
2009-09-02 03:23:51 +02:00
|
|
|
BitmapHashValue *cache_find_bitmap(Hashmap *bitmap_cache,
|
|
|
|
BitmapHashKey *key)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_find(bitmap_cache, key);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
2007-04-09 04:02:40 +02:00
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_bitmap_cache_init(ASS_Library *library)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *bitmap_cache;
|
2009-07-14 00:43:25 +02:00
|
|
|
bitmap_cache = hashmap_init(library,
|
2009-09-02 03:23:51 +02:00
|
|
|
sizeof(BitmapHashKey),
|
|
|
|
sizeof(BitmapHashValue),
|
2009-07-11 17:48:50 +02:00
|
|
|
0xFFFF + 13,
|
|
|
|
bitmap_hash_dtor, bitmap_compare,
|
|
|
|
bitmap_hash);
|
|
|
|
return bitmap_cache;
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void ass_bitmap_cache_done(Hashmap *bitmap_cache)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
hashmap_done(bitmap_cache);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_bitmap_cache_reset(Hashmap *bitmap_cache)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_Library *lib = bitmap_cache->library;
|
2009-07-14 00:43:25 +02:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
ass_bitmap_cache_done(bitmap_cache);
|
2009-07-14 00:43:25 +02:00
|
|
|
return ass_bitmap_cache_init(lib);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------
|
|
|
|
// glyph cache
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static void glyph_hash_dtor(void *key, size_t key_size, void *value,
|
|
|
|
size_t value_size)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
GlyphHashValue *v = value;
|
2009-07-11 17:48:50 +02:00
|
|
|
if (v->glyph)
|
|
|
|
FT_Done_Glyph(v->glyph);
|
|
|
|
if (v->outline_glyph)
|
|
|
|
FT_Done_Glyph(v->outline_glyph);
|
|
|
|
free(key);
|
|
|
|
free(value);
|
2008-01-17 17:50:19 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void *cache_add_glyph(Hashmap *glyph_cache, GlyphHashKey *key,
|
|
|
|
GlyphHashValue *val)
|
2008-01-17 17:50:19 +01:00
|
|
|
{
|
2010-11-11 05:48:08 +01:00
|
|
|
if (val->glyph && val->glyph->format == FT_GLYPH_FORMAT_BITMAP) {
|
|
|
|
FT_Bitmap *bitmap = &((FT_BitmapGlyph) val->glyph)->bitmap;
|
|
|
|
glyph_cache->cache_size += bitmap->rows * bitmap->pitch;
|
|
|
|
}
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_insert(glyph_cache, key, val);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get a glyph from glyph cache.
|
|
|
|
* \param key hash key
|
|
|
|
* \return requested hash val or 0 if not found
|
2009-07-11 17:48:50 +02:00
|
|
|
*/
|
2009-09-02 03:23:51 +02:00
|
|
|
GlyphHashValue *cache_find_glyph(Hashmap *glyph_cache,
|
|
|
|
GlyphHashKey *key)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_find(glyph_cache, key);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_glyph_cache_init(ASS_Library *library)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *glyph_cache;
|
|
|
|
glyph_cache = hashmap_init(library, sizeof(GlyphHashKey),
|
|
|
|
sizeof(GlyphHashValue),
|
2009-07-11 17:48:50 +02:00
|
|
|
0xFFFF + 13,
|
|
|
|
glyph_hash_dtor, glyph_compare, glyph_hash);
|
|
|
|
return glyph_cache;
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void ass_glyph_cache_done(Hashmap *glyph_cache)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
hashmap_done(glyph_cache);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_glyph_cache_reset(Hashmap *glyph_cache)
|
2007-04-09 04:02:40 +02:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_Library *lib = glyph_cache->library;
|
2009-07-14 00:43:25 +02:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
ass_glyph_cache_done(glyph_cache);
|
2009-07-14 00:43:25 +02:00
|
|
|
return ass_glyph_cache_init(lib);
|
2007-04-09 04:02:40 +02:00
|
|
|
}
|
2009-03-12 04:46:44 +01:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------
|
|
|
|
// composite cache
|
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
static void composite_hash_dtor(void *key, size_t key_size, void *value,
|
|
|
|
size_t value_size)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
CompositeHashValue *v = value;
|
2009-07-11 17:48:50 +02:00
|
|
|
free(v->a);
|
|
|
|
free(v->b);
|
|
|
|
free(key);
|
|
|
|
free(value);
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void *cache_add_composite(Hashmap *composite_cache,
|
|
|
|
CompositeHashKey *key,
|
|
|
|
CompositeHashValue *val)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_insert(composite_cache, key, val);
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Get a composite bitmap from composite cache.
|
|
|
|
* \param key hash key
|
|
|
|
* \return requested hash val or 0 if not found
|
|
|
|
*/
|
2009-09-02 03:23:51 +02:00
|
|
|
CompositeHashValue *cache_find_composite(Hashmap *composite_cache,
|
|
|
|
CompositeHashKey *key)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
return hashmap_find(composite_cache, key);
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_composite_cache_init(ASS_Library *library)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *composite_cache;
|
|
|
|
composite_cache = hashmap_init(library, sizeof(CompositeHashKey),
|
|
|
|
sizeof(CompositeHashValue),
|
2009-07-11 17:48:50 +02:00
|
|
|
0xFFFF + 13,
|
|
|
|
composite_hash_dtor, composite_compare,
|
|
|
|
composite_hash);
|
|
|
|
return composite_cache;
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
void ass_composite_cache_done(Hashmap *composite_cache)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-07-11 17:48:50 +02:00
|
|
|
hashmap_done(composite_cache);
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|
|
|
|
|
2009-09-02 03:23:51 +02:00
|
|
|
Hashmap *ass_composite_cache_reset(Hashmap *composite_cache)
|
2009-03-12 04:46:44 +01:00
|
|
|
{
|
2009-09-02 03:23:51 +02:00
|
|
|
ASS_Library *lib = composite_cache->library;
|
2009-07-14 00:43:25 +02:00
|
|
|
|
2009-07-11 17:48:50 +02:00
|
|
|
ass_composite_cache_done(composite_cache);
|
2009-07-14 00:43:25 +02:00
|
|
|
return ass_composite_cache_init(lib);
|
2009-03-12 04:46:44 +01:00
|
|
|
}
|