diff --git a/src/allocators.zig b/src/allocators.zig index 390fb25d88..cea0ae9b41 100644 --- a/src/allocators.zig +++ b/src/allocators.zig @@ -5,16 +5,14 @@ const Environment = @import("./env.zig"); const FixedBufferAllocator = std.heap.FixedBufferAllocator; const bun = @import("root").bun; -inline fn isSliceInBufferT(comptime T: type, slice: []const T, buffer: []const T) bool { +pub fn isSliceInBufferT(comptime T: type, slice: []const T, buffer: []const T) bool { return (@intFromPtr(buffer.ptr) <= @intFromPtr(slice.ptr) and (@intFromPtr(slice.ptr) + slice.len) <= (@intFromPtr(buffer.ptr) + buffer.len)); } -/// LMLJLSDKFjlsdkjflsdkjf /// Checks if a slice's pointer is contained within another slice. -/// /// If you need to make this generic, use isSliceInBufferT. -pub inline fn isSliceInBuffer(slice: []const u8, buffer: []const u8) bool { +pub fn isSliceInBuffer(slice: []const u8, buffer: []const u8) bool { return isSliceInBufferT(u8, slice, buffer); } diff --git a/src/bun.zig b/src/bun.zig index 9b8d5a4d18..4ecc0d393a 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -613,6 +613,7 @@ pub fn isHeapMemory(memory: anytype) bool { pub const Mimalloc = @import("./allocators/mimalloc.zig"); pub const isSliceInBuffer = allocators.isSliceInBuffer; +pub const isSliceInBufferT = allocators.isSliceInBufferT; pub inline fn sliceInBuffer(stable: string, value: string) string { if (allocators.sliceRange(stable, value)) |_| { diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 26c0808794..518dbe4af5 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -431,9 +431,11 @@ pub const RunCommand = struct { if (Environment.isWindows and bun.strings.hasSuffixComptime(executable, ".exe")) { std.debug.assert(std.fs.path.isAbsolute(executable)); - // Using @constCast is safe because we know that `direct_launch_buffer` is the data destination + // Using @constCast is safe because we know that + // `direct_launch_buffer` is the data destination that assumption is + // backed by the immediate assertion. var wpath = @constCast(bun.strings.toNTPath(&BunXFastPath.direct_launch_buffer, executable)); - std.debug.assert(bun.isSliceInBuffer(u16, wpath, &BunXFastPath.direct_launch_buffer)); + std.debug.assert(bun.isSliceInBufferT(u16, wpath, &BunXFastPath.direct_launch_buffer)); std.debug.assert(wpath.len > bun.windows.nt_object_prefix.len + ".exe".len); wpath.len += ".bunx".len - ".exe".len; @@ -1562,7 +1564,7 @@ pub const BunXFastPath = struct { /// If this returns, it implies the fast path cannot be taken fn tryLaunch(ctx: Command.Context, path_to_use: [:0]u16, env: *DotEnv.Loader, passthrough: []const []const u8) void { - std.debug.assert(bun.isSliceInBuffer(u16, path_to_use, &BunXFastPath.direct_launch_buffer)); + std.debug.assert(bun.isSliceInBufferT(u16, path_to_use, &BunXFastPath.direct_launch_buffer)); var command_line = BunXFastPath.direct_launch_buffer[path_to_use.len..]; debug("Attempting to find and load bunx file: '{}'", .{bun.fmt.utf16(path_to_use)});