From 48faa0e70672dca53efcdd1c4476cebc71b58eaa Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 21 Nov 2023 15:21:51 +0100 Subject: [PATCH] LibAccelGfx: Ensure capacity of vertices vector in draw_glyph_run() --- Userland/Libraries/LibAccelGfx/Painter.cpp | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibAccelGfx/Painter.cpp b/Userland/Libraries/LibAccelGfx/Painter.cpp index 4d88b3800b..796296093c 100644 --- a/Userland/Libraries/LibAccelGfx/Painter.cpp +++ b/Userland/Libraries/LibAccelGfx/Painter.cpp @@ -433,6 +433,7 @@ void Painter::prepare_glyph_texture(HashMap> co void Painter::draw_glyph_run(Vector const& glyph_run, Color const& color) { Vector vertices; + vertices.ensure_capacity(glyph_run.size() * 24); for (auto& glyph_or_emoji : glyph_run) { if (glyph_or_emoji.has()) { @@ -469,18 +470,20 @@ void Painter::draw_glyph_run(Vector const& glyph_run, Col auto s3 = texture_rect.bottom_right(); auto add_triangle = [&](auto& p1, auto& p2, auto& p3, auto& s1, auto& s2, auto& s3) { - vertices.append(p1.x()); - vertices.append(p1.y()); - vertices.append(s1.x()); - vertices.append(s1.y()); - vertices.append(p2.x()); - vertices.append(p2.y()); - vertices.append(s2.x()); - vertices.append(s2.y()); - vertices.append(p3.x()); - vertices.append(p3.y()); - vertices.append(s3.x()); - vertices.append(s3.y()); + vertices.unchecked_append(p1.x()); + vertices.unchecked_append(p1.y()); + vertices.unchecked_append(s1.x()); + vertices.unchecked_append(s1.y()); + + vertices.unchecked_append(p2.x()); + vertices.unchecked_append(p2.y()); + vertices.unchecked_append(s2.x()); + vertices.unchecked_append(s2.y()); + + vertices.unchecked_append(p3.x()); + vertices.unchecked_append(p3.y()); + vertices.unchecked_append(s3.x()); + vertices.unchecked_append(s3.y()); }; add_triangle(p0, p1, p3, s0, s1, s3);