From dd4d7d093907c74f0409e35b04390ab8524a9b9e Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Fri, 13 Jun 2025 16:50:47 +0200 Subject: [PATCH] LibGfx: Ensure capacity for glyph runs in `TextLayout` We can reserve the capacity for new glyph runs since we already know the glyph count. --- Libraries/LibGfx/TextLayout.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Libraries/LibGfx/TextLayout.cpp b/Libraries/LibGfx/TextLayout.cpp index 56d36cb7832..0b49f8b4c16 100644 --- a/Libraries/LibGfx/TextLayout.cpp +++ b/Libraries/LibGfx/TextLayout.cpp @@ -84,9 +84,9 @@ RefPtr shape_text(FloatPoint baseline_start, float letter_spacing, Utf auto* positions = hb_buffer_get_glyph_positions(buffer, &glyph_count); Vector glyph_run; + glyph_run.ensure_capacity(glyph_count); FloatPoint point = baseline_start; for (size_t i = 0; i < glyph_count; ++i) { - auto position = point - FloatPoint { 0, font.pixel_metrics().ascent } + FloatPoint { positions[i].x_offset, positions[i].y_offset } / text_shaping_resolution; @@ -98,10 +98,9 @@ RefPtr shape_text(FloatPoint baseline_start, float letter_spacing, Utf if (i != (glyph_count - 1)) point.translate_by(letter_spacing, 0); } - - auto run = adopt_ref(*new Gfx::GlyphRun(move(glyph_run), font, text_type, point.x() - baseline_start.x())); hb_buffer_reset(buffer); - return run; + + return adopt_ref(*new Gfx::GlyphRun(move(glyph_run), font, text_type, point.x() - baseline_start.x())); } float measure_text_width(Utf8View const& string, Gfx::Font const& font, ShapeFeatures const& features)