From bf6376240befb17fd26e29caf6f418796ab0d5f5 Mon Sep 17 00:00:00 2001 From: rcombs Date: Sun, 28 Apr 2024 02:16:48 -0700 Subject: ass_shaper: re-use the hb_buffer_t between calls Deleting and re-creating it turns out to be fairly expensive. --- libass/ass_shaper.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libass/ass_shaper.c b/libass/ass_shaper.c index 1d83757..896895d 100644 --- a/libass/ass_shaper.c +++ b/libass/ass_shaper.c @@ -65,6 +65,8 @@ struct ass_shaper { // Glyph metrics cache, to speed up shaping Cache *metrics_cache; + hb_buffer_t *buf; + #ifdef USE_FRIBIDI_EX_API FriBidiBracketType *btypes; bool bidi_brackets; @@ -142,6 +144,7 @@ void ass_shaper_free(ASS_Shaper *shaper) free(shaper->emblevels); free(shaper->cmap); free(shaper->pbase_dir); + hb_buffer_destroy(shaper->buf); free(shaper); } @@ -686,7 +689,7 @@ shape_harfbuzz_process_run(GlyphInfo *glyphs, hb_buffer_t *buf, int offset) static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len) { int i; - hb_buffer_t *buf = hb_buffer_create(); + hb_buffer_t *buf = shaper->buf; hb_segment_properties_t props = HB_SEGMENT_PROPERTIES_DEFAULT; // Initialize: skip all glyphs, this is undone later as needed @@ -745,8 +748,6 @@ static bool shape_harfbuzz(ASS_Shaper *shaper, GlyphInfo *glyphs, size_t len) hb_buffer_reset(buf); } - hb_buffer_destroy(buf); - return true; } @@ -1057,6 +1058,10 @@ ASS_Shaper *ass_shaper_new(Cache *metrics_cache) goto error; shaper->metrics_cache = metrics_cache; + shaper->buf = hb_buffer_create(); + if (!shaper->buf) + goto error; + return shaper; error: -- cgit v1.2.3