summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
diff options
context:
space:
mode:
authorDr.Smile <vabnick@gmail.com>2015-09-15 20:18:17 +0300
committerDr.Smile <vabnick@gmail.com>2016-06-30 23:13:53 +0300
commit25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e (patch)
treea5d82da3707fcf2801a960fbea70ccfca4052469 /libass/ass_font.c
parent7d05b1d3b8d08672bd7297516514396d1d1a846f (diff)
downloadlibass-25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e.tar.bz2
libass-25d65abce1a0fabe3c3bf81f1ee7ee7f24b91a4e.tar.xz
cache: switch to gradual cache clearing
Advantages over the old algorithm consist of the following. * There are no glitches due to full cache clearing. Items are arranged into linked list ordered by time of last use. Only the oldest items get deleted at the clearing event. * Each item now keeps track of number of references. Referenced cache values are immune to clearing. * Reduced amount of total cache memory for the same performance. * Reduced number of memory allocations per cache item.
Diffstat (limited to 'libass/ass_font.c')
-rw-r--r--libass/ass_font.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index 3d1b183..a4c45bd 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -229,32 +229,32 @@ ASS_Font *ass_font_new(Cache *font_cache, ASS_Library *library,
ASS_FontDesc *desc)
{
int error;
- ASS_Font *fontp;
- ASS_Font font;
-
- fontp = ass_cache_get(font_cache, desc);
- if (fontp)
- return fontp;
-
- font.library = library;
- font.ftlibrary = ftlibrary;
- font.shaper_priv = NULL;
- font.n_faces = 0;
- font.desc.family = strdup(desc->family);
- font.desc.bold = desc->bold;
- font.desc.italic = desc->italic;
- font.desc.vertical = desc->vertical;
-
- font.scale_x = font.scale_y = 1.;
- font.v.x = font.v.y = 0;
- font.size = 0.;
-
- error = add_face(fontsel, &font, 0);
+ ASS_Font *font;
+ if (ass_cache_get(font_cache, desc, &font))
+ return font;
+
+ font->library = library;
+ font->ftlibrary = ftlibrary;
+ font->shaper_priv = NULL;
+ font->n_faces = 0;
+ ASS_FontDesc *new_desc = ass_cache_get_key(font);
+ font->desc.family = new_desc->family = strdup(desc->family);
+ font->desc.bold = desc->bold;
+ font->desc.italic = desc->italic;
+ font->desc.vertical = desc->vertical;
+
+ font->scale_x = font->scale_y = 1.;
+ font->v.x = font->v.y = 0;
+ font->size = 0.;
+
+ error = add_face(fontsel, font, 0);
if (error == -1) {
- free(font.desc.family);
+ ass_cache_cancel(font);
+ free(font->desc.family);
return 0;
- } else
- return ass_cache_put(font_cache, &font.desc, &font);
+ }
+ ass_cache_commit(font);
+ return font;
}
/**
@@ -674,9 +674,9 @@ FT_Glyph ass_font_get_glyph(ASS_Font *font, uint32_t ch, int face_index,
}
/**
- * \brief Deallocate ASS_Font
+ * \brief Deallocate ASS_Font internals
**/
-void ass_font_free(ASS_Font *font)
+void ass_font_clear(ASS_Font *font)
{
int i;
if (font->shaper_priv)
@@ -686,7 +686,6 @@ void ass_font_free(ASS_Font *font)
FT_Done_Face(font->faces[i]);
}
free(font->desc.family);
- free(font);
}
/**