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++)
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);
#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
}
}
-done:
- hb_buffer_destroy (hb_buffer);
-
return make_fixnum (glyph_len);
}