Skip to content

Commit d629a14

Browse files
committed
Dir.realpathW: remove redundant buffer/copy
This same change was applied in 69007f0 but accidentally reverted in 7bf740e
1 parent 9aeabad commit d629a14

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/std/fs/Dir.zig

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,16 +1433,13 @@ pub fn realpathZ(self: Dir, pathname: [*:0]const u8, out_buffer: []u8) RealPathE
14331433
/// See also `Dir.realpath`, `realpathW`.
14341434
pub fn realpathW(self: Dir, pathname: []const u16, out_buffer: []u8) RealPathError![]u8 {
14351435
var wide_buf: [std.os.windows.PATH_MAX_WIDE]u16 = undefined;
1436-
14371436
const wide_slice = try self.realpathW2(pathname, &wide_buf);
14381437

1439-
var big_out_buf: [fs.max_path_bytes]u8 = undefined;
1440-
const end_index = std.unicode.wtf16LeToWtf8(&big_out_buf, wide_slice);
1441-
if (end_index > out_buffer.len)
1442-
return error.NameTooLong;
1443-
const result = out_buffer[0..end_index];
1444-
@memcpy(result, big_out_buf[0..end_index]);
1445-
return result;
1438+
const len = std.unicode.calcWtf8Len(wide_slice);
1439+
if (len > out_buffer.len) return error.NameTooLong;
1440+
1441+
const end_index = std.unicode.wtf16LeToWtf8(&out_buffer, wide_slice);
1442+
return out_buffer[0..end_index];
14461443
}
14471444

14481445
/// Windows-only. Same as `Dir.realpath` except

0 commit comments

Comments
 (0)