commit cf0f6dd17fc9c534b11c6a3f3f6e448702a9a93a (tree)
parent 9fd63daff2f6b98c2c7ae3a2668d2fa6cd92589c
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Tue, 7 Apr 2026 17:22:02 -0700
Io.Threaded: Reduce dirRealPathFileWindows stack usage by 64KiB
This effectively reinstates the changes made in https://github.com/ziglang/zig/pull/23657 that were lost in the transition to std.Io
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
@@ -6090,12 +6090,19 @@ fn dirRealPathFileWindows(userdata: ?*anyopaque, dir: Dir, sub_path: []const u8,
}
};
defer windows.CloseHandle(h_file);
- return realPathWindows(h_file, out_buffer);
+
+ // We can re-use the path buffer for the WTF-16 representation since
+ // we don't need the prefixed path anymore
+ return realPathWindowsBuf(h_file, out_buffer, &path_name_w.data);
}
fn realPathWindows(h_file: windows.HANDLE, out_buffer: []u8) File.RealPathError!usize {
var wide_buf: [windows.PATH_MAX_WIDE]u16 = undefined;
- const wide_slice = try GetFinalPathNameByHandle(h_file, .{}, &wide_buf);
+ return realPathWindowsBuf(h_file, out_buffer, &wide_buf);
+}
+
+fn realPathWindowsBuf(h_file: windows.HANDLE, out_buffer: []u8, wtf16_buffer: []u16) File.RealPathError!usize {
+ const wide_slice = try GetFinalPathNameByHandle(h_file, .{}, wtf16_buffer);
const len = std.unicode.calcWtf8Len(wide_slice);
if (len > out_buffer.len)