diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-27 17:45:13 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2026-04-27 17:45:13 +0200 |
| commit | 3b0e9424a66058da82d11d432da886ec7b6ce7eb (patch) | |
| tree | 0ad906e3b7d945405cdfeb9ff95b02546e1ed4bb /src/eval/Image.zig | |
| parent | ef5c0341ca15f6862294802103b02992b29609e8 (diff) | |
perf(eval): reduce memory syscall
Diffstat (limited to 'src/eval/Image.zig')
| -rw-r--r-- | src/eval/Image.zig | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/eval/Image.zig b/src/eval/Image.zig index aa30585..53478b6 100644 --- a/src/eval/Image.zig +++ b/src/eval/Image.zig @@ -17,16 +17,7 @@ pub fn init(alloc: Allocator, src: []const u8) !*Self { } pub fn element(self: *Self) Element { - return .{ .ptr = self, .vtable = .{ .deinit = destroy, .html = 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 = html } }; } fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML { @@ -38,12 +29,13 @@ fn html(context: *anyopaque, alloc: Allocator) HTML.Error!HTML { } test "html" { - const alloc = std.testing.allocator; + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); + defer arena.deinit(); + var alloc = arena.allocator(); const expect = std.testing.expect; const eql = std.mem.eql; var img = try init(alloc, "foo"); - defer img.deinit(alloc); const h = try img.element().renderHTML(alloc); defer alloc.free(h); try expect(eql(u8, h, "<img src=\"foo\">")); |
