1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-07 20:30:32 -08:00

Avoid allocating a Lisp_Save_Value in ftfont.c

* src/ftfont.c (struct ftfont_cache_data): New member face_refcount.
(ftfont_lookup_cache): Clear it when initializing.
Use make_mint_ptr, since this typically avoids the need to
allocate a Lisp_Save_Value as refcount is now stored elsewhere.
(ftfont_open2, ftfont_close): Manipulate the reference
count in the struct, not in the save object.
This commit is contained in:
Paul Eggert 2018-06-14 15:59:08 -07:00
parent 3f0a8a2e14
commit 888bf9877d

View file

@ -345,6 +345,7 @@ struct ftfont_cache_data
{
FT_Face ft_face;
FcCharSet *fc_charset;
intptr_t face_refcount;
};
static Lisp_Object
@ -371,17 +372,15 @@ ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for)
{
if (NILP (ft_face_cache))
ft_face_cache = CALLN (Fmake_hash_table, QCtest, Qequal);
cache_data = xmalloc (sizeof *cache_data);
cache_data->ft_face = NULL;
cache_data->fc_charset = NULL;
val = make_save_ptr_int (cache_data, 0);
cache_data = xzalloc (sizeof *cache_data);
val = make_mint_ptr (cache_data);
cache = Fcons (Qnil, val);
Fputhash (key, cache, ft_face_cache);
}
else
{
val = XCDR (cache);
cache_data = XSAVE_POINTER (val, 0);
cache_data = xmint_pointer (val);
}
if (cache_for == FTFONT_CACHE_FOR_ENTITY)
@ -447,7 +446,7 @@ ftfont_get_fc_charset (Lisp_Object entity)
cache = ftfont_lookup_cache (entity, FTFONT_CACHE_FOR_CHARSET);
val = XCDR (cache);
cache_data = XSAVE_POINTER (val, 0);
cache_data = xmint_pointer (val);
return cache_data->fc_charset;
}
@ -1118,9 +1117,9 @@ ftfont_open2 (struct frame *f,
filename = XCAR (val);
idx = XCDR (val);
val = XCDR (cache);
cache_data = XSAVE_POINTER (XCDR (cache), 0);
cache_data = xmint_pointer (XCDR (cache));
ft_face = cache_data->ft_face;
if (XSAVE_INTEGER (val, 1) > 0)
if (cache_data->face_refcount > 0)
{
/* FT_Face in this cache is already used by the different size. */
if (FT_New_Size (ft_face, &ft_size) != 0)
@ -1136,14 +1135,14 @@ ftfont_open2 (struct frame *f,
size = pixel_size;
if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0)
{
if (XSAVE_INTEGER (val, 1) == 0)
if (cache_data->face_refcount == 0)
{
FT_Done_Face (ft_face);
cache_data->ft_face = NULL;
}
return Qnil;
}
set_save_integer (val, 1, XSAVE_INTEGER (val, 1) + 1);
cache_data->face_refcount++;
ASET (font_object, FONT_FILE_INDEX, filename);
font = XFONT_OBJECT (font_object);
@ -1255,11 +1254,10 @@ ftfont_close (struct font *font)
cache = ftfont_lookup_cache (val, FTFONT_CACHE_FOR_FACE);
eassert (CONSP (cache));
val = XCDR (cache);
set_save_integer (val, 1, XSAVE_INTEGER (val, 1) - 1);
if (XSAVE_INTEGER (val, 1) == 0)
struct ftfont_cache_data *cache_data = xmint_pointer (val);
cache_data->face_refcount--;
if (cache_data->face_refcount == 0)
{
struct ftfont_cache_data *cache_data = XSAVE_POINTER (val, 0);
FT_Done_Face (cache_data->ft_face);
#ifdef HAVE_LIBOTF
if (ftfont_info->otf)