mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 12:44:43 +00:00
wrap assertions with comptime if
This commit is contained in:
@@ -23,6 +23,8 @@ const js = @import("../js/js.zig");
|
||||
|
||||
const EventTarget = @import("EventTarget.zig");
|
||||
|
||||
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||
|
||||
const Key = struct {
|
||||
target: *EventTarget,
|
||||
handler: Handler,
|
||||
@@ -32,12 +34,16 @@ const Key = struct {
|
||||
/// See `Context.hash`.
|
||||
fn fuse(self: *const Key) u64 {
|
||||
// Check if we have 3 bits available from alignment of 8.
|
||||
lp.assert(@alignOf(EventTarget) == 8, "Key.fuse: incorrect alignment", .{
|
||||
.event_target_alignment = @alignOf(EventTarget),
|
||||
});
|
||||
if (comptime IS_DEBUG) {
|
||||
lp.assert(@alignOf(EventTarget) == 8, "Key.fuse: incorrect alignment", .{
|
||||
.event_target_alignment = @alignOf(EventTarget),
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user