diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-28 15:08:02 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-28 15:08:02 +0200 |
| commit | 3b1e6547d069d7c438af551a4989972802a895ee (patch) | |
| tree | 7c32e8fcac432539888e0cdb598f495316b0772d /src/parser.zig | |
| parent | e154408e8ddeaee83242002f4c7af68b29d3a677 (diff) | |
perf(html): reduce memory usage
Diffstat (limited to 'src/parser.zig')
| -rw-r--r-- | src/parser.zig | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/parser.zig b/src/parser.zig index db91641..72b803f 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -21,21 +21,21 @@ pub const Error = error{FeatureNotSupported} || callout.Error || Allocator.Error; -pub const Document = *Element.Root; +pub const Document = Element.Root; -pub fn parseReader(parent: Allocator, r: *std.io.Reader) !Document { +pub fn parseReader(parent: Allocator, r: *std.io.Reader) !*Document { var l = try Lexer.initReader(parent, r); defer parent.free(l.iter.bytes); return gen(parent, &l); } -pub fn parse(parent: Allocator, content: []const u8) Error!Document { +pub fn parse(parent: Allocator, content: []const u8) Error!*Document { var l = try Lexer.init(content); return gen(parent, &l); } -fn gen(parent: Allocator, l: *Lexer) Error!Document { - var root = try Element.Root.init(parent); +fn gen(parent: Allocator, l: *Lexer) Error!*Document { + var root = try Document.init(parent); errdefer root.deinit(); const alloc = root.allocator(); base: while (l.peek()) |it| { @@ -75,6 +75,7 @@ fn doTest(alloc: Allocator, t: []const u8, v: []const u8) !void { test "parse multilines" { const alloc = std.testing.allocator; + try doTest(alloc, "hello world", "<p>hello world</p>"); try doTest(alloc, \\hello \\world |
