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/eval/html/Literal.zig | |
| parent | e154408e8ddeaee83242002f4c7af68b29d3a677 (diff) | |
perf(html): reduce memory usage
Diffstat (limited to 'src/eval/html/Literal.zig')
| -rw-r--r-- | src/eval/html/Literal.zig | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/eval/html/Literal.zig b/src/eval/html/Literal.zig index d3b697f..ccad004 100644 --- a/src/eval/html/Literal.zig +++ b/src/eval/html/Literal.zig @@ -1,22 +1,37 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const List = std.ArrayList; const html = @import("html.zig"); const Element = @import("Element.zig"); +const Node = Element.Node; const Error = Element.Error; literal: []const u8, +node: Node = .{ + .ptr = undefined, + .vtable = .{ .element = fromNode }, +}, const Self = @This(); pub fn init(alloc: Allocator, literal: []const u8) Error!*Element.Literal { const v = try alloc.create(Self); v.* = .{ .literal = try html.escape(alloc, literal) }; + v.node.ptr = v; return v; } pub fn element(self: *Self) Element { - return .{ .vtable = .{ .render = Self.render }, .ptr = self }; + return .{ .vtable = .{ .render = render, .node = getNode }, .ptr = self }; +} + +fn getNode(context: *anyopaque) *Node { + const self: *Self = @ptrCast(@alignCast(context)); + return &self.node; +} + +fn fromNode(context: *anyopaque) Element { + const self: *Self = @ptrCast(@alignCast(context)); + return self.element(); } fn render(context: *anyopaque, alloc: Allocator) Error![]const u8 { |
