>From da5f1e7113ee4143c40050232c618c89b8873dc7 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 7 Jun 2018 19:12:28 -0700 Subject: [PATCH 05/10] 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. --- src/ftfont.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/ftfont.c b/src/ftfont.c index a53467000f..d50fa39fa7 100644 --- a/src/ftfont.c +++ b/src/ftfont.c @@ -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) -- 2.17.1