From dd24e86dad0402917b1713d1afeefaf65c3d1e51 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 15 Oct 2026 21:57:59 +0200 Subject: zilch: reusing results in processing loop --- src/zilch/Env/root.zig | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/zilch/Env/root.zig') diff --git a/src/zilch/Env/root.zig b/src/zilch/Env/root.zig index 5ab3fbd..5244830 100644 --- a/src/zilch/Env/root.zig +++ b/src/zilch/Env/root.zig @@ -20,6 +20,8 @@ const Self = @This(); pub const default: Self = .{ .gpa = std.heap.wasm_allocator }; pub fn call(self: *Self, function: Function, args: anytype) AnyFuture { + const id = self.calls.items.len; + self.calls.append(self.gpa, .{ .kind = function.id, .num_args = args.len, @@ -31,9 +33,13 @@ pub fn call(self: *Self, function: Function, args: anytype) AnyFuture { const result = self.pool.create(self.gpa) catch |err| return .{ .err = err }; errdefer self.pool.destroy(result); - result.kind = .uninit; self.results.append(self.gpa, result) catch |err| return .{ .err = err }; - return .{ .result = result }; + return .{ + .unresolved = .{ + .id = id, + .value = result, + }, + }; } pub fn flush(self: *Self) void { @@ -48,11 +54,8 @@ pub fn flush(self: *Self) void { self.results.clearRetainingCapacity(); } -pub fn release(self: *Self, future: AnyFuture) void { - switch (future) { - .err => {}, - .result => |result| self.pool.destroy(result), - } +pub fn release(self: *Self, value: *Value) void { + self.pool.destroy(value); } pub fn deinit(self: *Self) void { -- cgit v1.2.3-70-g09d2