wrap assertions with comptime if

This commit is contained in:
Halil Durak
2026-02-11 16:45:31 +03:00
parent 6d2ef9be5d
commit ea69b3b4e3

View File

@@ -23,6 +23,8 @@ const js = @import("../js/js.zig");
const EventTarget = @import("EventTarget.zig"); const EventTarget = @import("EventTarget.zig");
const IS_DEBUG = @import("builtin").mode == .Debug;
const Key = struct { const Key = struct {
target: *EventTarget, target: *EventTarget,
handler: Handler, handler: Handler,
@@ -32,12 +34,16 @@ const Key = struct {
/// See `Context.hash`. /// See `Context.hash`.
fn fuse(self: *const Key) u64 { fn fuse(self: *const Key) u64 {
// Check if we have 3 bits available from alignment of 8. // Check if we have 3 bits available from alignment of 8.
lp.assert(@alignOf(EventTarget) == 8, "Key.fuse: incorrect alignment", .{ if (comptime IS_DEBUG) {
.event_target_alignment = @alignOf(EventTarget), lp.assert(@alignOf(EventTarget) == 8, "Key.fuse: incorrect alignment", .{
}); .event_target_alignment = @alignOf(EventTarget),
});
}
const ptr = @intFromPtr(self.target) >> 3; const ptr = @intFromPtr(self.target) >> 3;
lp.assert(ptr < (1 << 57), "Key.fuse: pointer overflow", .{ .ptr = ptr }); if (comptime IS_DEBUG) {
lp.assert(ptr < (1 << 57), "Key.fuse: pointer overflow", .{ .ptr = ptr });
}
return ptr | (@as(u64, @intFromEnum(self.handler)) << 57); return ptr | (@as(u64, @intFromEnum(self.handler)) << 57);
} }
}; };