diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-26 22:07:03 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-26 22:07:03 +0200 |
| commit | 1ce415538f202bf1319ebb0ff6e76aa54f983343 (patch) | |
| tree | de7febaf453855229581fdc2dbcc92fd2bd1bed3 /src/link.zig | |
| parent | dca42e27fe9c7d28c72bb6cb8e5cc4ec481572e8 (diff) | |
perf(parse): reduce realloc for figcaptions
Diffstat (limited to 'src/link.zig')
| -rw-r--r-- | src/link.zig | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/link.zig b/src/link.zig index 50e89f5..3333e76 100644 --- a/src/link.zig +++ b/src/link.zig @@ -81,13 +81,8 @@ pub fn parseImage(alloc: Allocator, l: *Lexer) ImageError!Element { } const p = try paragraph.parse(alloc, l); errdefer p.deinit(alloc); - el.source = p; const p_el: *Element.paragraph.Block = @ptrCast(@alignCast(p.ptr)); - defer p_el.deinit(alloc); - const in = try Element.Empty.init(alloc); - errdefer in.deinit(alloc); - in.content = try p_el.content.clone(alloc); - el.source = in.element(); + el.source = (try p_el.toEmpty(alloc)).element(); return el.element(); } @@ -110,4 +105,12 @@ test "parse image" { try doTest(parseImage, alloc, "", "<figure><img src=\"src\"></figure>"); try doTest(parseImage, alloc, "", "<figure><img src=\"src\" alt=\"alt\"></figure>"); + + try doTest(parseImage, alloc, + \\ + \\caption + \\on multiple lines! + \\ + \\not in + , "<figure><img src=\"foo\" alt=\"bar\"><figcaption>caption on multiple lines!</figcaption></figure>"); } |
