diff options
Diffstat (limited to 'src/watcher.zig')
-rw-r--r-- | src/watcher.zig | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/watcher.zig b/src/watcher.zig index e3b3600ad..aded993e8 100644 --- a/src/watcher.zig +++ b/src/watcher.zig @@ -73,7 +73,7 @@ pub const INotify = struct { // it includes alignment / padding // but it is a sentineled value // so we can just trim it to the first null byte - return bun.sliceTo(@ptrFromInt([*:0]u8, @intFromPtr(&this.name_len) + @sizeOf(u32)), 0)[0.. :0]; + return bun.sliceTo(@as([*:0]u8, @ptrFromInt(@intFromPtr(&this.name_len) + @sizeOf(u32))), 0)[0.. :0]; } }; pub var inotify_fd: EventListIndex = 0; @@ -131,13 +131,13 @@ pub const INotify = struct { Futex.wait(&watch_count, 0, null) catch unreachable; const rc = std.os.system.read( inotify_fd, - @ptrCast([*]u8, @alignCast(@alignOf([*]u8), &eventlist)), + @as([*]u8, @ptrCast(@alignCast(&eventlist))), @sizeOf(EventListBuffer), ); switch (std.os.errno(rc)) { .SUCCESS => { - var len = @intCast(usize, rc); + var len = @as(usize, @intCast(rc)); if (len == 0) return &[_]*INotifyEvent{}; @@ -154,12 +154,12 @@ pub const INotify = struct { while (true) { const new_rc = std.os.system.read( inotify_fd, - @ptrCast([*]u8, @alignCast(@alignOf([*]u8), &eventlist)) + len, + @as([*]u8, @ptrCast(@alignCast(&eventlist))) + len, @sizeOf(EventListBuffer) - len, ); switch (std.os.errno(new_rc)) { .SUCCESS => { - len += @intCast(usize, new_rc); + len += @as(usize, @intCast(new_rc)); }, .AGAIN => continue, .INTR => continue, @@ -186,7 +186,7 @@ pub const INotify = struct { var i: u32 = 0; while (i < len) : (i += @sizeOf(INotifyEvent)) { @setRuntimeSafety(false); - var event = @ptrCast(*INotifyEvent, @alignCast(@alignOf(*INotifyEvent), eventlist[i..][0..@sizeOf(INotifyEvent)])); + var event = @as(*INotifyEvent, @ptrCast(@alignCast(eventlist[i..][0..@sizeOf(INotifyEvent)]))); i += event.name_len; eventlist_ptrs[count] = event; @@ -284,7 +284,7 @@ pub const WatchEvent = struct { pub fn ignoreINotifyEvent(event: INotify.INotifyEvent) bool { var stack: WatchEvent = undefined; stack.fromINotify(event, 0); - return @bitCast(std.meta.Int(.unsigned, @bitSizeOf(Op)), stack.op) == 0; + return @as(std.meta.Int(.unsigned, @bitSizeOf(Op)), @bitCast(stack.op)) == 0; } pub fn names(this: WatchEvent, buf: []?[:0]u8) []?[:0]u8 { @@ -319,7 +319,7 @@ pub const WatchEvent = struct { .rename = (kevent.fflags & (std.c.NOTE_RENAME | std.c.NOTE_LINK)) > 0, .write = (kevent.fflags & std.c.NOTE_WRITE) > 0, }, - .index = @truncate(WatchItemIndex, kevent.udata), + .index = @as(WatchItemIndex, @truncate(kevent.udata)), }; } @@ -377,7 +377,7 @@ pub fn NewWatcher(comptime ContextType: type) type { var evict_list: [WATCHER_MAX_LIST]WatchItemIndex = undefined; pub fn getHash(filepath: string) HashType { - return @truncate(HashType, bun.hash(filepath)); + return @as(HashType, @truncate(bun.hash(filepath))); } pub fn init(ctx: ContextType, fs: *Fs.FileSystem, allocator: std.mem.Allocator) !*Watcher { @@ -464,7 +464,7 @@ pub fn NewWatcher(comptime ContextType: type) type { if (comptime kind == .directory) { for (parents) |parent| { if (parent == hash) { - evict_list[evict_list_i] = @truncate(WatchItemIndex, parent); + evict_list[evict_list_i] = @as(WatchItemIndex, @truncate(parent)); evict_list_i += 1; } } @@ -538,9 +538,9 @@ pub fn NewWatcher(comptime ContextType: type) type { var timespec = std.os.timespec{ .tv_sec = 0, .tv_nsec = 100_000 }; const extra = std.os.system.kevent( DarwinWatcher.fd, - @as([*]KEvent, changelist[@intCast(usize, count_)..].ptr), + @as([*]KEvent, changelist[@as(usize, @intCast(count_))..].ptr), 0, - @as([*]KEvent, changelist[@intCast(usize, count_)..].ptr), + @as([*]KEvent, changelist[@as(usize, @intCast(count_))..].ptr), remain, ×pec, @@ -549,7 +549,7 @@ pub fn NewWatcher(comptime ContextType: type) type { count_ += extra; } - var changes = changelist[0..@intCast(usize, @max(0, count_))]; + var changes = changelist[0..@as(usize, @intCast(@max(0, count_)))]; var watchevents = this.watch_events[0..changes.len]; var out_len: usize = 0; if (changes.len > 0) { @@ -603,13 +603,13 @@ pub fn NewWatcher(comptime ContextType: type) type { for (slice) |event| { watchevents[watch_event_id].fromINotify( event.*, - @intCast( + @as( WatchItemIndex, - std.mem.indexOfScalar( + @intCast(std.mem.indexOfScalar( INotify.EventListIndex, eventlist_index, event.watch_descriptor, - ) orelse continue, + ) orelse continue), ), ); temp_name_list[temp_name_off] = if (event.name_len > 0) @@ -661,7 +661,7 @@ pub fn NewWatcher(comptime ContextType: type) type { pub fn indexOf(this: *Watcher, hash: HashType) ?u32 { for (this.watchlist.items(.hash), 0..) |other, i| { if (hash == other) { - return @truncate(u32, i); + return @as(u32, @truncate(i)); } } return null; @@ -725,10 +725,10 @@ pub fn NewWatcher(comptime ContextType: type) type { event.fflags = std.c.NOTE_WRITE | std.c.NOTE_RENAME | std.c.NOTE_DELETE; // id - event.ident = @intCast(usize, fd); + event.ident = @as(usize, @intCast(fd)); // Store the hash for fast filtering later - event.udata = @intCast(usize, watchlist_id); + event.udata = @as(usize, @intCast(watchlist_id)); var events: [1]KEvent = .{event}; // This took a lot of work to figure out the right permutation @@ -777,7 +777,7 @@ pub fn NewWatcher(comptime ContextType: type) type { if (fd_ > 0) break :brk fd_; const dir = try std.fs.cwd().openIterableDir(file_path, .{}); - break :brk @truncate(StoredFileDescriptorType, dir.dir.fd); + break :brk @as(StoredFileDescriptorType, @truncate(dir.dir.fd)); }; const parent_hash = Watcher.getHash(Fs.PathName.init(file_path).dirWithTrailingSlash()); @@ -807,10 +807,10 @@ pub fn NewWatcher(comptime ContextType: type) type { event.fflags = std.c.NOTE_WRITE | std.c.NOTE_RENAME | std.c.NOTE_DELETE; // id - event.ident = @intCast(usize, fd); + event.ident = @as(usize, @intCast(fd)); // Store the hash for fast filtering later - event.udata = @intCast(usize, watchlist_id); + event.udata = @as(usize, @intCast(watchlist_id)); var events: [1]KEvent = .{event}; // This took a lot of work to figure out the right permutation @@ -845,7 +845,7 @@ pub fn NewWatcher(comptime ContextType: type) type { .kind = .directory, .package_json = null, }); - return @truncate(WatchItemIndex, this.watchlist.len - 1); + return @as(WatchItemIndex, @truncate(this.watchlist.len - 1)); } pub inline fn isEligibleDirectory(this: *Watcher, dir: string) bool { @@ -898,18 +898,18 @@ pub fn NewWatcher(comptime ContextType: type) type { if (dir_fd > 0) { var fds = watchlist_slice.items(.fd); if (std.mem.indexOfScalar(StoredFileDescriptorType, fds, dir_fd)) |i| { - parent_watch_item = @truncate(WatchItemIndex, i); + parent_watch_item = @as(WatchItemIndex, @truncate(i)); } } if (parent_watch_item == null) { const hashes = watchlist_slice.items(.hash); if (std.mem.indexOfScalar(HashType, hashes, parent_dir_hash)) |i| { - parent_watch_item = @truncate(WatchItemIndex, i); + parent_watch_item = @as(WatchItemIndex, @truncate(i)); } } } - try this.watchlist.ensureUnusedCapacity(this.allocator, 1 + @intCast(usize, @intFromBool(parent_watch_item == null))); + try this.watchlist.ensureUnusedCapacity(this.allocator, 1 + @as(usize, @intCast(@intFromBool(parent_watch_item == null)))); if (autowatch_parent_dir) { parent_watch_item = parent_watch_item orelse try this.appendDirectoryAssumeCapacity(dir_fd, parent_dir, parent_dir_hash, copy_file_path); |