aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2018-06-14 15:59:08 -0700
committerPaul Eggert2018-06-14 17:13:39 -0700
commit888bf9877d466dbb65aec821bede9ac49e12798f (patch)
tree0791497a3092ada47413b8bf4cbc5825b6f77d3c /src
parent3f0a8a2e14669cf4a1f56e97f8b1299fced79796 (diff)
downloademacs-888bf9877d466dbb65aec821bede9ac49e12798f.tar.gz
emacs-888bf9877d466dbb65aec821bede9ac49e12798f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ftfont.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/ftfont.c b/src/ftfont.c
index a53467000f3..d50fa39fa7b 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -345,6 +345,7 @@ struct ftfont_cache_data
345{ 345{
346 FT_Face ft_face; 346 FT_Face ft_face;
347 FcCharSet *fc_charset; 347 FcCharSet *fc_charset;
348 intptr_t face_refcount;
348}; 349};
349 350
350static Lisp_Object 351static Lisp_Object
@@ -371,17 +372,15 @@ ftfont_lookup_cache (Lisp_Object key, enum ftfont_cache_for cache_for)
371 { 372 {
372 if (NILP (ft_face_cache)) 373 if (NILP (ft_face_cache))
373 ft_face_cache = CALLN (Fmake_hash_table, QCtest, Qequal); 374 ft_face_cache = CALLN (Fmake_hash_table, QCtest, Qequal);
374 cache_data = xmalloc (sizeof *cache_data); 375 cache_data = xzalloc (sizeof *cache_data);
375 cache_data->ft_face = NULL; 376 val = make_mint_ptr (cache_data);
376 cache_data->fc_charset = NULL;
377 val = make_save_ptr_int (cache_data, 0);
378 cache = Fcons (Qnil, val); 377 cache = Fcons (Qnil, val);
379 Fputhash (key, cache, ft_face_cache); 378 Fputhash (key, cache, ft_face_cache);
380 } 379 }
381 else 380 else
382 { 381 {
383 val = XCDR (cache); 382 val = XCDR (cache);
384 cache_data = XSAVE_POINTER (val, 0); 383 cache_data = xmint_pointer (val);
385 } 384 }
386 385
387 if (cache_for == FTFONT_CACHE_FOR_ENTITY) 386 if (cache_for == FTFONT_CACHE_FOR_ENTITY)
@@ -447,7 +446,7 @@ ftfont_get_fc_charset (Lisp_Object entity)
447 446
448 cache = ftfont_lookup_cache (entity, FTFONT_CACHE_FOR_CHARSET); 447 cache = ftfont_lookup_cache (entity, FTFONT_CACHE_FOR_CHARSET);
449 val = XCDR (cache); 448 val = XCDR (cache);
450 cache_data = XSAVE_POINTER (val, 0); 449 cache_data = xmint_pointer (val);
451 return cache_data->fc_charset; 450 return cache_data->fc_charset;
452} 451}
453 452
@@ -1118,9 +1117,9 @@ ftfont_open2 (struct frame *f,
1118 filename = XCAR (val); 1117 filename = XCAR (val);
1119 idx = XCDR (val); 1118 idx = XCDR (val);
1120 val = XCDR (cache); 1119 val = XCDR (cache);
1121 cache_data = XSAVE_POINTER (XCDR (cache), 0); 1120 cache_data = xmint_pointer (XCDR (cache));
1122 ft_face = cache_data->ft_face; 1121 ft_face = cache_data->ft_face;
1123 if (XSAVE_INTEGER (val, 1) > 0) 1122 if (cache_data->face_refcount > 0)
1124 { 1123 {
1125 /* FT_Face in this cache is already used by the different size. */ 1124 /* FT_Face in this cache is already used by the different size. */
1126 if (FT_New_Size (ft_face, &ft_size) != 0) 1125 if (FT_New_Size (ft_face, &ft_size) != 0)
@@ -1136,14 +1135,14 @@ ftfont_open2 (struct frame *f,
1136 size = pixel_size; 1135 size = pixel_size;
1137 if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0) 1136 if (FT_Set_Pixel_Sizes (ft_face, size, size) != 0)
1138 { 1137 {
1139 if (XSAVE_INTEGER (val, 1) == 0) 1138 if (cache_data->face_refcount == 0)
1140 { 1139 {
1141 FT_Done_Face (ft_face); 1140 FT_Done_Face (ft_face);
1142 cache_data->ft_face = NULL; 1141 cache_data->ft_face = NULL;
1143 } 1142 }
1144 return Qnil; 1143 return Qnil;
1145 } 1144 }
1146 set_save_integer (val, 1, XSAVE_INTEGER (val, 1) + 1); 1145 cache_data->face_refcount++;
1147 1146
1148 ASET (font_object, FONT_FILE_INDEX, filename); 1147 ASET (font_object, FONT_FILE_INDEX, filename);
1149 font = XFONT_OBJECT (font_object); 1148 font = XFONT_OBJECT (font_object);
@@ -1255,11 +1254,10 @@ ftfont_close (struct font *font)
1255 cache = ftfont_lookup_cache (val, FTFONT_CACHE_FOR_FACE); 1254 cache = ftfont_lookup_cache (val, FTFONT_CACHE_FOR_FACE);
1256 eassert (CONSP (cache)); 1255 eassert (CONSP (cache));
1257 val = XCDR (cache); 1256 val = XCDR (cache);
1258 set_save_integer (val, 1, XSAVE_INTEGER (val, 1) - 1); 1257 struct ftfont_cache_data *cache_data = xmint_pointer (val);
1259 if (XSAVE_INTEGER (val, 1) == 0) 1258 cache_data->face_refcount--;
1259 if (cache_data->face_refcount == 0)
1260 { 1260 {
1261 struct ftfont_cache_data *cache_data = XSAVE_POINTER (val, 0);
1262
1263 FT_Done_Face (cache_data->ft_face); 1261 FT_Done_Face (cache_data->ft_face);
1264#ifdef HAVE_LIBOTF 1262#ifdef HAVE_LIBOTF
1265 if (ftfont_info->otf) 1263 if (ftfont_info->otf)