aboutsummaryrefslogtreecommitdiff
path: root/src/eval/Element.zig
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-04-27 17:45:13 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2026-04-27 17:45:13 +0200
commit3b0e9424a66058da82d11d432da886ec7b6ce7eb (patch)
tree0ad906e3b7d945405cdfeb9ff95b02546e1ed4bb /src/eval/Element.zig
parentef5c0341ca15f6862294802103b02992b29609e8 (diff)
perf(eval): reduce memory syscall
Diffstat (limited to 'src/eval/Element.zig')
-rw-r--r--src/eval/Element.zig43
1 files changed, 4 insertions, 39 deletions
diff --git a/src/eval/Element.zig b/src/eval/Element.zig
index 265ccf1..72b6d7d 100644
--- a/src/eval/Element.zig
+++ b/src/eval/Element.zig
@@ -5,6 +5,7 @@ pub const paragraph = @import("paragraph.zig");
pub const Title = @import("Title.zig");
pub const list = @import("list.zig");
pub const Image = @import("Image.zig");
+pub const Root = @import("Root.zig");
const blocks = @import("blocks.zig");
pub const Code = blocks.Code;
pub const Figure = blocks.Figure;
@@ -12,7 +13,6 @@ pub const Figure = blocks.Figure;
const Element = @This();
vtable: struct {
- deinit: *const fn (*anyopaque, Allocator) void,
html: *const fn (*anyopaque, Allocator) HTML.Error!HTML,
},
ptr: *anyopaque,
@@ -24,10 +24,6 @@ pub fn renderHTML(self: Element, alloc: Allocator) HTML.Error![]const u8 {
return el.render(alloc);
}
-pub fn deinit(self: Element, alloc: Allocator) void {
- self.vtable.deinit(self.ptr, alloc);
-}
-
pub fn html(self: Element, alloc: Allocator) HTML.Error!HTML {
return self.vtable.html(self.ptr, alloc);
}
@@ -44,18 +40,7 @@ pub const Empty = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = Self.html } };
- }
-
- pub fn deinit(self: *Self, alloc: Allocator) void {
- destroy(self, alloc);
- }
-
- fn destroy(context: *anyopaque, alloc: Allocator) void {
- const self: *Self = @ptrCast(@alignCast(context));
- for (self.content.items) |it| it.deinit(alloc);
- self.content.deinit(alloc);
- alloc.destroy(self);
+ return .{ .ptr = self, .vtable = .{ .html = Self.html } };
}
fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML {
@@ -79,16 +64,7 @@ pub const Literal = struct {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = Self.html } };
- }
-
- pub fn deinit(self: *Self, alloc: Allocator) void {
- destroy(self, alloc);
- }
-
- fn destroy(context: *anyopaque, alloc: Allocator) void {
- const self: *Self = @ptrCast(@alignCast(context));
- alloc.destroy(self);
+ return .{ .ptr = self, .vtable = .{ .html = Self.html } };
}
fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML {
@@ -110,11 +86,7 @@ pub fn Simple(comptime tag: []const u8) type {
}
pub fn element(self: *Self) Element {
- return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = Self.html } };
- }
-
- pub fn deinit(self: *Self, alloc: Allocator) void {
- destroy(self, alloc);
+ return .{ .ptr = self, .vtable = .{ .html = Self.html } };
}
pub fn toTag(self: *Self, alloc: Allocator, comptime target: []const u8) !*Simple(target) {
@@ -135,13 +107,6 @@ pub fn Simple(comptime tag: []const u8) type {
alloc.destroy(self);
}
- fn destroy(context: *anyopaque, alloc: Allocator) void {
- var self: *Self = @ptrCast(@alignCast(context));
- for (self.content.items) |it| it.deinit(alloc);
- self.content.deinit(alloc);
- alloc.destroy(self);
- }
-
fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML {
const self: *Self = @ptrCast(@alignCast(context));
var el = try HTML.Content.init(alloc, tag);