aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-28 19:37:37 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-28 19:37:37 +0200
commitd9e37656e83d7d3c25709795ab7ccccca0071254 (patch)
tree622789be5f608f39d6fdd9b9b99a16209f3b1d7f /src/link.zig
parent3b1e6547d069d7c438af551a4989972802a895ee (diff)
perf(eval): reduce memory usage
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/link.zig b/src/link.zig
index 612ee8c..ecfad83 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -17,7 +17,7 @@ pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
const v = l.next().?;
if (v.kind != .link) return Error.InvalidLink;
if (!eql(u8, v.content, "[")) return (try Element.Literal.init(alloc, v.content)).element();
- var el = try Element.Empty.init(alloc);
+ var el = try Element.Root.init(alloc);
while (l.peek()) |next| switch (next.kind) {
.weak_delimiter, .strong_delimiter => return Error.InvalidLink,
.link => {
@@ -26,18 +26,20 @@ pub fn parse(alloc: Allocator, l: *Lexer) Error!Element {
break;
},
else => {
- const in = try content.parse(alloc, l);
- try el.content.append(alloc, in);
+ const in = try content.parse(el.allocator(), l);
+ el.append(in);
},
};
const href = l.next() orelse return Error.InvalidLink;
if (href.kind != .literal) return Error.InvalidLink;
const finisher = l.next() orelse return Error.InvalidLink;
if (!finisher.equals(.link, ")")) return Error.InvalidLink;
- const in: Element = if (el.content.items.len > 0)
+ const in: Element = if (el.content.first != null)
el.element()
- else
- (try Element.Literal.init(alloc, href.content)).element();
+ else blk: {
+ el.deinit();
+ break :blk (try Element.Literal.init(alloc, href.content)).element();
+ };
return (try Link.init(alloc, in, href.content)).element();
}
@@ -74,7 +76,7 @@ pub fn parseImage(alloc: Allocator, l: *Lexer) ImageError!Element {
}
const p = try paragraph.parse(alloc, l);
const p_el: *Element.paragraph.Block = @ptrCast(@alignCast(p.ptr));
- el.caption = (try p_el.toEmpty(alloc)).element();
+ el.caption = (try p_el.toRoot(alloc)).element();
return el.element();
}