[vector] Preallocate SVG buffers in render and subset paths

This commit is contained in:
Behdad Esfahbod committed 2026-02-24 13:17:09 -03:00
1 parent 96cbf70c4b
commit 9ab5ecaac8
2 files changed
+13

No files matched your search

+5
View File
@@ -360,6 +360,7 @@ hb_svg_subset_glyph_image (hb_blob_t *image,
int defs_open_i = hb_svg_find_substr (svg, len, 0, "<defs", 5);
int defs_close_i = hb_svg_find_substr (svg, len, 0, "</defs>", 7);
hb_vector_t<hb_svg_defs_entry_t> defs_entries;
defs_entries.alloc (64);
if (defs_open_i >= 0 && defs_close_i > defs_open_i)
{
int defs_gt = hb_svg_find_substr (svg, len, (unsigned) defs_open_i, ">", 1);
@@ -397,10 +398,12 @@ hb_svg_subset_glyph_image (hb_blob_t *image,
}
hb_vector_t<hb_svg_id_span_t> needed_ids;
needed_ids.alloc (16);
if (!hb_svg_collect_refs (svg + glyph_start, glyph_end - glyph_start, &needed_ids))
return false;
hb_vector_t<unsigned> chosen_defs;
chosen_defs.alloc (16);
for (unsigned qi = 0; qi < needed_ids.length; qi++)
{
const auto &need = needed_ids.arrayZ[qi];
@@ -429,6 +432,8 @@ hb_svg_subset_glyph_image (hb_blob_t *image,
if (prefix_len <= 0 || (unsigned) prefix_len >= sizeof (prefix))
return false;
body_dst->alloc (body_dst->length + (glyph_end - glyph_start) + (unsigned) prefix_len + 32);
for (unsigned i = 0; i < chosen_defs.length; i++)
{
const auto &e = defs_entries.arrayZ[chosen_defs.arrayZ[i]];
+8
View File
@@ -1566,6 +1566,10 @@ hb_vector_draw_render (hb_vector_draw_t *draw)
hb_vector_t<char> out;
hb_svg_recover_recycled_buffer (draw->recycled_blob, &out);
unsigned estimated = draw->defs.length +
(draw->body.length ? draw->body.length : draw->path.length) +
256;
out.alloc (estimated);
hb_svg_append_str (&out, "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"");
hb_svg_append_num (&out, draw->extents.x, draw->precision);
hb_svg_append_c (&out, ' ');
@@ -1946,6 +1950,10 @@ hb_vector_paint_render (hb_vector_paint_t *paint)
hb_vector_t<char> out;
hb_svg_recover_recycled_buffer (paint->recycled_blob, &out);
unsigned estimated = paint->defs.length +
paint->group_stack.arrayZ[0].length +
320;
out.alloc (estimated);
hb_svg_append_str (&out, "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"");
hb_svg_append_num (&out, paint->extents.x, paint->precision);
hb_svg_append_c (&out, ' ');