diff options
| author | Khaled Hosny | 2018-12-24 03:56:16 +0200 |
|---|---|---|
| committer | Khaled Hosny | 2018-12-24 03:56:16 +0200 |
| commit | a93668fc4384de66895b04fd54ed5edfbe3e47d6 (patch) | |
| tree | 8114f8ea0a0ef3e433f6474a08c97962406544ff | |
| parent | bb603936c6ea702a8f7c3930c92eeffbc79bdcdd (diff) | |
| download | emacs-a93668fc4384de66895b04fd54ed5edfbe3e47d6.tar.gz emacs-a93668fc4384de66895b04fd54ed5edfbe3e47d6.zip | |
Cache HarfBuzz buffer
Potentially faster and less memory allocations. I did not do any
measurements though, so possibly a micro optimization.
| -rw-r--r-- | src/ftfont.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/ftfont.c b/src/ftfont.c index 7498b775654..bc37a6ae0d1 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, | |||
| 2805 | hb_glyph_info_t *info; | 2805 | hb_glyph_info_t *info; |
| 2806 | hb_glyph_position_t *pos; | 2806 | hb_glyph_position_t *pos; |
| 2807 | 2807 | ||
| 2808 | /* TODO: cache the buffer for slightly better performance and less | 2808 | /* Cache the HarfBuzz buffer for better performance and less allocations. |
| 2809 | * allocations. */ | 2809 | * We intentionally never destroy the buffer. */ |
| 2810 | hb_buffer_t *hb_buffer = hb_buffer_create (); | 2810 | static hb_buffer_t *hb_buffer = NULL; |
| 2811 | if (! hb_buffer) | ||
| 2812 | { | ||
| 2813 | hb_buffer = hb_buffer_create (); | ||
| 2814 | hb_unicode_funcs_t* ufuncs = get_hb_unicode_funcs(); | ||
| 2815 | hb_buffer_set_unicode_funcs(hb_buffer, ufuncs); | ||
| 2816 | } | ||
| 2817 | |||
| 2818 | hb_buffer_clear_contents (hb_buffer); | ||
| 2811 | hb_buffer_pre_allocate (hb_buffer, text_len); | 2819 | hb_buffer_pre_allocate (hb_buffer, text_len); |
| 2812 | 2820 | ||
| 2813 | for (i = 0; i < text_len; i++) | 2821 | 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, | |||
| 2823 | 2831 | ||
| 2824 | text_len = i; | 2832 | text_len = i; |
| 2825 | if (!text_len) | 2833 | if (!text_len) |
| 2826 | goto done; | 2834 | return Qnil; |
| 2827 | |||
| 2828 | hb_unicode_funcs_t* ufuncs = get_hb_unicode_funcs(); | ||
| 2829 | hb_buffer_set_unicode_funcs(hb_buffer, ufuncs); | ||
| 2830 | 2835 | ||
| 2831 | hb_buffer_set_content_type (hb_buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); | 2836 | hb_buffer_set_content_type (hb_buffer, HB_BUFFER_CONTENT_TYPE_UNICODE); |
| 2832 | hb_buffer_set_cluster_level (hb_buffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); | 2837 | 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, | |||
| 2842 | #endif | 2847 | #endif |
| 2843 | 2848 | ||
| 2844 | if (!hb_shape_full (hb_font, hb_buffer, NULL, 0, NULL)) | 2849 | if (!hb_shape_full (hb_font, hb_buffer, NULL, 0, NULL)) |
| 2845 | goto done; | 2850 | return Qnil; |
| 2846 | 2851 | ||
| 2847 | glyph_len = hb_buffer_get_length (hb_buffer); | 2852 | glyph_len = hb_buffer_get_length (hb_buffer); |
| 2848 | /* FIXME: number of output glyphs can legitimately be larger than number of | 2853 | /* 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, | |||
| 2906 | } | 2911 | } |
| 2907 | } | 2912 | } |
| 2908 | 2913 | ||
| 2909 | done: | ||
| 2910 | hb_buffer_destroy (hb_buffer); | ||
| 2911 | |||
| 2912 | return make_fixnum (glyph_len); | 2914 | return make_fixnum (glyph_len); |
| 2913 | } | 2915 | } |
| 2914 | 2916 | ||