Skip to content

Commit

Permalink
Remove redundant env allocation in CallbackDispatcher (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackalcooper authored Jan 4, 2025
1 parent 4d89373 commit f13df7c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions native/src/pass.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const CallbackDispatcher = extern struct {
e.enif_free_env(this.env);
beam.allocator.destroy(this);
}
fn initialize(_: mlir_capi.Context.T, userData: ?*anyopaque) callconv(.C) mlir_capi.LogicalResult.T {
const this: *@This() = @ptrCast(@alignCast(userData));
this.*.env = e.enif_alloc_env() orelse return c.mlirLogicalResultFailure();
fn initialize(_: mlir_capi.Context.T, _: ?*anyopaque) callconv(.C) mlir_capi.LogicalResult.T {
return c.mlirLogicalResultSuccess();
}
fn clone(userData: ?*anyopaque) callconv(.C) ?*anyopaque {
Expand Down Expand Up @@ -67,10 +65,10 @@ const CallbackDispatcher = extern struct {
const passID = c.mlirTypeIDAllocatorAllocateTypeID(typeIDAllocator.?);
const nDependentDialects = 0;
const dependentDialects = null;
const bp: *@This() = try beam.allocator.create(@This());
const bp_env = e.enif_alloc_env() orelse return Error.@"Fail to allocate BEAM environment";
bp.* = @This(){ .handler = handler, .env = bp_env, .run_fn = e.enif_make_copy(bp_env, args[5]) };
return beaverPassCreateWrap(env, .{ construct, destruct, initialize, clone, run, passID, name, argument, description, op_name, nDependentDialects, dependentDialects, bp });
const this: *@This() = try beam.allocator.create(@This());
const this_env = e.enif_alloc_env() orelse return Error.@"Fail to allocate BEAM environment";
this.* = @This(){ .handler = handler, .env = this_env, .run_fn = e.enif_make_copy(this_env, args[5]) };
return beaverPassCreateWrap(env, .{ construct, destruct, initialize, clone, run, passID, name, argument, description, op_name, nDependentDialects, dependentDialects, this });
}
};

Expand Down

0 comments on commit f13df7c

Please sign in to comment.