aboutsummaryrefslogtreecommitdiff
path: root/src/zilch/Env/root.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-15 21:57:59 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-15 21:57:59 +0200
commitdd24e86dad0402917b1713d1afeefaf65c3d1e51 (patch)
tree7f6c9f4d23eb8e60b6b7374233f33423cff40708 /src/zilch/Env/root.zig
parenta1dc55be6e695a1c04e5e9e0f1ce7406a5dd3dff (diff)
zilch: reusing results in processing loop
Diffstat (limited to 'src/zilch/Env/root.zig')
-rw-r--r--src/zilch/Env/root.zig17
1 files changed, 10 insertions, 7 deletions
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 {