emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] harfbuzz a93668f 1/2: Cache HarfBuzz buffer


From: Khaled Hosny
Subject: [Emacs-diffs] harfbuzz a93668f 1/2: Cache HarfBuzz buffer
Date: Sun, 23 Dec 2018 21:01:37 -0500 (EST)

branch: harfbuzz
commit a93668fc4384de66895b04fd54ed5edfbe3e47d6
Author: Khaled Hosny <address@hidden>
Commit: Khaled Hosny <address@hidden>

    Cache HarfBuzz buffer
    
    Potentially faster and less memory allocations. I did not do any
    measurements though, so possibly a micro optimization.
---
 src/ftfont.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/ftfont.c b/src/ftfont.c
index 7498b77..bc37a6a 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -2805,9 +2805,17 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face 
ft_face, hb_font_t *hb_font,
   hb_glyph_info_t *info;
   hb_glyph_position_t *pos;
 
-  /* TODO: cache the buffer for slightly better performance and less
-   * allocations. */
-  hb_buffer_t *hb_buffer = hb_buffer_create ();
+  /* Cache the HarfBuzz buffer for better performance and less allocations.
+   * We intentionally never destroy the buffer. */
+  static hb_buffer_t *hb_buffer = NULL;
+  if (! hb_buffer)
+    {
+      hb_buffer = hb_buffer_create ();
+      hb_unicode_funcs_t* ufuncs = get_hb_unicode_funcs();
+      hb_buffer_set_unicode_funcs(hb_buffer, ufuncs);
+    }
+
+  hb_buffer_clear_contents (hb_buffer);
   hb_buffer_pre_allocate (hb_buffer, text_len);
 
   for (i = 0; i < text_len; i++)
@@ -2823,10 +2831,7 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face 
ft_face, hb_font_t *hb_font,
 
   text_len = i;
   if (!text_len)
-    goto done;
-
-  hb_unicode_funcs_t* ufuncs = get_hb_unicode_funcs();
-  hb_buffer_set_unicode_funcs(hb_buffer, ufuncs);
+    return Qnil;
 
   hb_buffer_set_content_type (hb_buffer, HB_BUFFER_CONTENT_TYPE_UNICODE);
   hb_buffer_set_cluster_level (hb_buffer, 
HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
@@ -2842,7 +2847,7 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face 
ft_face, hb_font_t *hb_font,
 #endif
 
   if (!hb_shape_full (hb_font, hb_buffer, NULL, 0, NULL))
-    goto done;
+    return Qnil;
 
   glyph_len = hb_buffer_get_length (hb_buffer);
   /* FIXME: number of output glyphs can legitimately be larger than number of
@@ -2906,9 +2911,6 @@ ftfont_shape_by_hb (Lisp_Object lgstring, FT_Face 
ft_face, hb_font_t *hb_font,
       }
     }
 
-done:
-  hb_buffer_destroy (hb_buffer);
-
   return make_fixnum (glyph_len);
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]