From cf0f6dd17fc9c534b11c6a3f3f6e448702a9a93a Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Tue, 7 Apr 2026 17:22:02 -0700 Subject: [PATCH] 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 --- lib/std/Io/Threaded.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 0bec8a068f59241d17c8e4fb70919b3c79db1988..9dd20449e1f451a0c75716d3482dc5c5186d0dd3 100644 --- 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) -- 2.54.0