]> granicus.if.org Git - libass/commitdiff
cache: fix size tracking and emptying
authorGrigori Goronzy <greg@blackbox>
Mon, 27 Jun 2011 17:42:56 +0000 (19:42 +0200)
committerGrigori Goronzy <greg@blackbox>
Mon, 27 Jun 2011 17:51:32 +0000 (19:51 +0200)
libass/ass_cache.c
libass/ass_cache.h

index 15f7376f47e380554f23efe6553e7f3c80ae5918..8d42e615865470144d14126153686798824bd817 100644 (file)
@@ -229,6 +229,8 @@ void *ass_cache_put(Cache *cache, void *key, void *value)
     cache->items++;
     if (cache->size_func)
         cache->cache_size += cache->size_func(value, cache->value_size);
+    else
+        cache->cache_size++;
 
     return (*item)->value;
 }
@@ -248,12 +250,12 @@ void *ass_cache_get(Cache *cache, void *key)
     return NULL;
 }
 
-size_t ass_cache_empty(Cache *cache, size_t max_size)
+int ass_cache_empty(Cache *cache, size_t max_size)
 {
     int i;
 
     if (cache->cache_size < max_size)
-        return cache->cache_size;
+        return 0;
 
     for (i = 0; i < cache->buckets; i++) {
         CacheItem *item = cache->map[i];
@@ -268,7 +270,7 @@ size_t ass_cache_empty(Cache *cache, size_t max_size)
 
     cache->items = cache->hits = cache->misses = cache->cache_size = 0;
 
-    return 0;
+    return 1;
 }
 
 void ass_cache_stats(Cache *cache, size_t *size, unsigned *hits,
index 0ad7cae2c0f847b7c030d04e2e75b1413d50dcbf..05903e72e0ac002bbd8eb16d1c16b38b9a6bafe8 100644 (file)
 
 typedef struct cache Cache;
 
+// cache values
+
+typedef struct {
+    Bitmap *bm;               // the actual bitmaps
+    Bitmap *bm_o;
+    Bitmap *bm_s;
+} BitmapHashValue;
+
+typedef struct {
+    unsigned char *a;
+    unsigned char *b;
+} CompositeHashValue;
+
+typedef struct {
+    FT_Library lib;
+    FT_Outline *outline;
+    FT_Outline *border;
+    FT_BBox bbox_scaled;        // bbox after scaling, but before rotation
+    FT_Vector advance;          // 26.6, advance distance to the next outline in line
+    int asc, desc;              // ascender/descender
+} OutlineHashValue;
+
 // Create definitions for bitmap, outline and composite hash keys
 #define CREATE_STRUCT_DEFINITIONS
 #include "ass_cache_template.h"
@@ -49,34 +71,12 @@ typedef struct outline_hash_key {
     } u;
 } OutlineHashKey;
 
-// cache values
-
-typedef struct {
-    Bitmap *bm;               // the actual bitmaps
-    Bitmap *bm_o;
-    Bitmap *bm_s;
-} BitmapHashValue;
-
-typedef struct {
-    unsigned char *a;
-    unsigned char *b;
-} CompositeHashValue;
-
-typedef struct {
-    FT_Library lib;
-    FT_Outline *outline;
-    FT_Outline *border;
-    FT_BBox bbox_scaled;        // bbox after scaling, but before rotation
-    FT_Vector advance;          // 26.6, advance distance to the next outline in line
-    int asc, desc;              // ascender/descender
-} OutlineHashValue;
-
 Cache *ass_cache_create(HashFunction hash_func, HashCompare compare_func,
                         CacheItemDestructor destruct_func, ItemSize size_func,
                         size_t key_size, size_t value_size);
 void *ass_cache_put(Cache *cache, void *key, void *value);
 void *ass_cache_get(Cache *cache, void *key);
-size_t ass_cache_empty(Cache *cache, size_t max_size);
+int ass_cache_empty(Cache *cache, size_t max_size);
 void ass_cache_stats(Cache *cache, size_t *size, unsigned *hits,
                      unsigned *misses, unsigned *count);
 void ass_cache_done(Cache *cache);