From 1ce415538f202bf1319ebb0ff6e76aa54f983343 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Sun, 26 Apr 2026 22:07:03 +0200 Subject: perf(parse): reduce realloc for figcaptions --- src/eval/Element.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/eval/Element.zig') diff --git a/src/eval/Element.zig b/src/eval/Element.zig index a8b424d..355e971 100644 --- a/src/eval/Element.zig +++ b/src/eval/Element.zig @@ -113,6 +113,24 @@ pub fn Simple(comptime tag: []const u8) type { destroy(self, alloc); } + pub fn toTag(self: *Self, alloc: Allocator, comptime target: []const u8) !*Simple(target) { + const el = try Simple(target).init(alloc); + self.conv(alloc, &el.content); + return el; + } + + pub fn toEmpty(self: *Self, alloc: Allocator) !*Empty { + const el = try Empty.init(alloc); + self.conv(alloc, &el.content); + return el; + } + + fn conv(self: *Self, alloc: Allocator, arr: *std.ArrayList(Element)) void { + arr.deinit(alloc); + arr.* = self.content; + alloc.destroy(self); + } + fn destroy(context: *anyopaque, alloc: Allocator) void { var self: *Self = @ptrCast(@alignCast(context)); for (self.content.items) |it| it.deinit(alloc); -- cgit v1.2.3