summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrcombs <rcombs@rcombs.me>2024-04-28 02:16:48 -0700
committerrcombs <rcombs@rcombs.me>2024-04-29 17:48:29 -0700
commitbf6376240befb17fd26e29caf6f418796ab0d5f5 (patch)
treeaecbd1d13e28bfe512f7a385a1886591faa75026
parentbec1ed13f2478b97b391ebe829ca2f32a7252bba (diff)
downloadlibass-bf6376240befb17fd26e29caf6f418796ab0d5f5.tar.bz2
libass-bf6376240befb17fd26e29caf6f418796ab0d5f5.tar.xz
ass_shaper: re-use the hb_buffer_t between calls
Deleting and re-creating it turns out to be fairly expensive.
-rw-r--r--libass/ass_shaper.c11
1 files 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: