diff options
author | 2023-07-11 19:14:34 -0700 | |
---|---|---|
committer | 2023-07-11 19:14:34 -0700 | |
commit | cbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch) | |
tree | 43a00501f3cde495967e116f0b660777051551f8 /src/router.zig | |
parent | 1f900cff453700b19bca2acadfe26da4468c1282 (diff) | |
parent | 34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff) | |
download | bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.gz bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.zst bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.zip |
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
Diffstat (limited to 'src/router.zig')
-rw-r--r-- | src/router.zig | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/src/router.zig b/src/router.zig index 3e0dc0dba..8ed16f102 100644 --- a/src/router.zig +++ b/src/router.zig @@ -28,7 +28,7 @@ const URLPath = @import("./http/url_path.zig"); const PathnameScanner = @import("./url.zig").PathnameScanner; const CodepointIterator = @import("./string_immutable.zig").CodepointIterator; -const index_route_hash = @truncate(u32, std.hash.Wyhash.hash(0, "$$/index-route$$-!(@*@#&*%-901823098123")); +const index_route_hash = @truncate(u32, bun.hash("$$/index-route$$-!(@*@#&*%-901823098123")); const arbitrary_max_route = 4096; pub const Param = struct { @@ -335,7 +335,7 @@ const RouteLoader = struct { const relative_dir = FileSystem.instance.relative(base_dir, config.dir); if (!strings.hasPrefixComptime(relative_dir, "..")) { - route_dirname_len = @truncate(u16, relative_dir.len + @as(usize, @boolToInt(config.dir[config.dir.len - 1] != std.fs.path.sep))); + route_dirname_len = @truncate(u16, relative_dir.len + @as(usize, @intFromBool(config.dir[config.dir.len - 1] != std.fs.path.sep))); } var this = RouteLoader{ @@ -356,7 +356,7 @@ const RouteLoader = struct { .allocator = allocator, }; - std.sort.sort(*Route, this.all_routes.items, Route.Sorter{}, Route.Sorter.sortByName); + std.sort.block(*Route, this.all_routes.items, Route.Sorter{}, Route.Sorter.sortByName); var route_list = RouteIndex.List{}; route_list.setCapacity(allocator, this.all_routes.items.len) catch unreachable; @@ -365,7 +365,7 @@ const RouteLoader = struct { var index_id: ?usize = null; for (this.all_routes.items, 0..) |route, i| { - if (@enumToInt(route.kind) > @enumToInt(Pattern.Tag.static) and dynamic_start == null) { + if (@intFromEnum(route.kind) > @intFromEnum(Pattern.Tag.static) and dynamic_start == null) { dynamic_start = i; } @@ -521,14 +521,14 @@ pub const TinyPtr = packed struct { pub fn from(parent: string, in: string) TinyPtr { if (in.len == 0 or parent.len == 0) return TinyPtr{}; - const right = @ptrToInt(in.ptr) + in.len; - const end = @ptrToInt(parent.ptr) + parent.len; + const right = @intFromPtr(in.ptr) + in.len; + const end = @intFromPtr(parent.ptr) + parent.len; if (comptime Environment.isDebug) { std.debug.assert(end < right); } const length = @max(end, right) - right; - const offset = @max(@ptrToInt(in.ptr), @ptrToInt(parent.ptr)) - @ptrToInt(parent.ptr); + const offset = @max(@intFromPtr(in.ptr), @intFromPtr(parent.ptr)) - @intFromPtr(parent.ptr); return TinyPtr{ .offset = @truncate(u16, offset), .len = @truncate(u16, length) }; } }; @@ -605,7 +605,7 @@ pub const Route = struct { // - static routes go first because we match those first // - dynamic, catch-all, and optional catch all routes are sorted lexicographically, except "[", "]" appear last so that deepest routes are tested first // - catch-all & optional catch-all appear at the end because we want to test those at the end. - return switch (std.math.order(@enumToInt(a.kind), @enumToInt(b.kind))) { + return switch (std.math.order(@intFromEnum(a.kind), @intFromEnum(b.kind))) { .eq => switch (a.kind) { // static + dynamic are sorted alphabetically .static, .dynamic => @call( @@ -676,7 +676,7 @@ pub const Route = struct { buf = buf[base.len..]; bun.copy(u8, buf, extname); buf = buf[extname.len..]; - break :brk route_file_buf[0 .. @ptrToInt(buf.ptr) - @ptrToInt(&route_file_buf)]; + break :brk route_file_buf[0 .. @intFromPtr(buf.ptr) - @intFromPtr(&route_file_buf)]; }; var name = public_path[0 .. public_path.len - extname.len]; @@ -711,7 +711,7 @@ pub const Route = struct { has_uppercase = public_path[name_i] >= 'A' and public_path[name_i] <= 'Z'; } - const name_offset = @ptrToInt(name.ptr) - @ptrToInt(public_path.ptr); + const name_offset = @intFromPtr(name.ptr) - @intFromPtr(public_path.ptr); if (has_uppercase) { public_path = FileSystem.DirnameStore.instance.append(@TypeOf(public_path), public_path) catch unreachable; @@ -770,7 +770,7 @@ pub const Route = struct { .full_hash = if (is_index) index_route_hash else - @truncate(u32, std.hash.Wyhash.hash(0, name)), + @truncate(u32, bun.hash(name)), .param_count = validation_result.param_count, .kind = validation_result.kind, .abs_path = entry.abs_path, @@ -1183,7 +1183,7 @@ const Pattern = struct { var count: u16 = 0; var offset: RoutePathInt = 0; std.debug.assert(input.len > 0); - var kind: u4 = @enumToInt(Tag.static); + var kind: u4 = @intFromEnum(Tag.static); const end = @truncate(u32, input.len - 1); while (offset < end) { const pattern: Pattern = Pattern.initUnhashed(input, offset) catch |err| { @@ -1247,11 +1247,11 @@ const Pattern = struct { return null; }; offset = pattern.len; - kind = @max(@enumToInt(@as(Pattern.Tag, pattern.value)), kind); - count += @intCast(u16, @boolToInt(@enumToInt(@as(Pattern.Tag, pattern.value)) > @enumToInt(Pattern.Tag.static))); + kind = @max(@intFromEnum(@as(Pattern.Tag, pattern.value)), kind); + count += @intCast(u16, @intFromBool(@intFromEnum(@as(Pattern.Tag, pattern.value)) > @intFromEnum(Pattern.Tag.static))); } - return ValidationResult{ .param_count = count, .kind = @intToEnum(Tag, kind) }; + return ValidationResult{ .param_count = count, .kind = @enumFromInt(Tag, kind) }; } pub fn eql(a: Pattern, b: Pattern) bool { @@ -1369,7 +1369,7 @@ const Pattern = struct { i += 1; } - if (@enumToInt(tag) > @enumToInt(Tag.dynamic) and i <= end) return error.CatchAllMustBeAtTheEnd; + if (@intFromEnum(tag) > @intFromEnum(Tag.dynamic) and i <= end) return error.CatchAllMustBeAtTheEnd; return Pattern{ .len = @min(i + 1, end), |