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/Void.zig | |
| parent | e154408e8ddeaee83242002f4c7af68b29d3a677 (diff) | |
perf(html): reduce memory usage
Diffstat (limited to 'src/eval/html/Void.zig')
| -rw-r--r-- | src/eval/html/Void.zig | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/eval/html/Void.zig b/src/eval/html/Void.zig index ec35fc7..99bc923 100644 --- a/src/eval/html/Void.zig +++ b/src/eval/html/Void.zig @@ -3,12 +3,17 @@ 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; alloc: Allocator, tag: []const u8, attributes: std.StringArrayHashMap([]const u8), class_list: std.BufSet, +node: Node = .{ + .ptr = undefined, + .vtable = .{ .element = fromNode }, +}, pub const Self = @This(); @@ -20,11 +25,12 @@ pub fn init(alloc: Allocator, tag: []const u8) Error!*Self { .attributes = .init(alloc), .class_list = .init(alloc), }; + 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 }; } pub fn setAttribute(self: *Self, k: []const u8, v: []const u8) Error!void { @@ -51,6 +57,16 @@ pub fn removeClass(self: *Self, v: []const u8) void { self.class_list.remove(v); } +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 { const self: *Self = @ptrCast(@alignCast(context)); const attr = try renderAttribute(alloc, &self.attributes, &self.class_list); |
