[util/hb-shape] Free cached resources on termination
This commit is contained in:
parent
ad03f34df7
commit
d7541f7b55
|
@ -681,10 +681,7 @@ output_options_t::add_options (option_parser_t *parser)
|
|||
}
|
||||
|
||||
|
||||
const char *font_options_t::cached_font_path = nullptr;
|
||||
hb_blob_t *font_options_t::cached_blob = nullptr;
|
||||
unsigned font_options_t::cached_face_index = (unsigned) -1;
|
||||
hb_face_t *font_options_t::cached_face = nullptr;
|
||||
font_options_t::cache_t font_options_t::cache {};
|
||||
|
||||
hb_font_t *
|
||||
font_options_t::get_font () const
|
||||
|
@ -708,8 +705,8 @@ font_options_t::get_font () const
|
|||
#endif
|
||||
}
|
||||
|
||||
if (cached_font_path && 0 == strcmp (cached_font_path, font_path))
|
||||
blob = hb_blob_reference (cached_blob);
|
||||
if (cache.font_path && 0 == strcmp (cache.font_path, font_path))
|
||||
blob = hb_blob_reference (cache.blob);
|
||||
else
|
||||
{
|
||||
blob = hb_blob_create_from_file_or_fail (font_path);
|
||||
|
@ -719,27 +716,27 @@ font_options_t::get_font () const
|
|||
|
||||
/* Update caches. */
|
||||
|
||||
hb_face_destroy (cached_face);
|
||||
cached_face = nullptr;
|
||||
cached_face_index = (unsigned) -1;
|
||||
hb_face_destroy (cache.face);
|
||||
cache.face = nullptr;
|
||||
cache.face_index = (unsigned) -1;
|
||||
|
||||
free ((char *) cached_font_path);
|
||||
cached_font_path = strdup (font_path);
|
||||
hb_blob_destroy (cached_blob);
|
||||
cached_blob = hb_blob_reference (blob);
|
||||
free ((char *) cache.font_path);
|
||||
cache.font_path = strdup (font_path);
|
||||
hb_blob_destroy (cache.blob);
|
||||
cache.blob = hb_blob_reference (blob);
|
||||
}
|
||||
|
||||
hb_face_t *face = nullptr;
|
||||
if (cached_face_index == face_index)
|
||||
face = hb_face_reference (cached_face);
|
||||
if (cache.face_index == face_index)
|
||||
face = hb_face_reference (cache.face);
|
||||
else
|
||||
{
|
||||
face = hb_face_create (blob, face_index);
|
||||
hb_blob_destroy (blob);
|
||||
|
||||
cached_face_index = face_index;
|
||||
hb_face_destroy (cached_face);
|
||||
cached_face = hb_face_reference (face);
|
||||
cache.face_index = face_index;
|
||||
hb_face_destroy (cache.face);
|
||||
cache.face = hb_face_reference (face);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -507,10 +507,20 @@ struct font_options_t : option_group_t
|
|||
private:
|
||||
mutable hb_font_t *font;
|
||||
|
||||
static const char *cached_font_path;
|
||||
static hb_blob_t *cached_blob;
|
||||
static unsigned cached_face_index;
|
||||
static hb_face_t *cached_face;
|
||||
static struct cache_t
|
||||
{
|
||||
~cache_t ()
|
||||
{
|
||||
free ((void *) font_path);
|
||||
hb_blob_destroy (blob);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
const char *font_path = nullptr;
|
||||
hb_blob_t *blob = nullptr;
|
||||
unsigned face_index = (unsigned) -1;
|
||||
hb_face_t *face = nullptr;
|
||||
} cache;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue