authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 14:52:14-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-26 19:58:56-08:00
logeb29737d5d77b195b1e030e6bcb99ed0e30ede33
tree5d208969bc75d36e82e4f16492d8b317984dcf6f
parent6dcf95139118ec7e91222f7e15f5ea07a51c67f3

std.Io.Threaded: more efficient statx mask check


1 files changed, 17 insertions(+), 41 deletions(-)

lib/std/Io/Threaded.zig+17-41
......@@ -1919,23 +1919,7 @@ fn dirStatFileLinux(
19191919 try current_thread.beginSyscall();
19201920 while (true) {
19211921 var statx = std.mem.zeroes(linux.Statx);
1922 const rc = sys.statx(
1923 dir.handle,
1924 sub_path_posix,
1925 flags,
1926 .{
1927 .TYPE = true,
1928 .MODE = true,
1929 .ATIME = true,
1930 .MTIME = true,
1931 .CTIME = true,
1932 .INO = true,
1933 .SIZE = true,
1934 .NLINK = true,
1935 },
1936 &statx,
1937 );
1938 switch (sys.errno(rc)) {
1922 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_mask, &statx))) {
19391923 .SUCCESS => {
19401924 current_thread.endSyscall();
19411925 return statFromLinux(&statx);
......@@ -2170,22 +2154,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
21702154 try current_thread.beginSyscall();
21712155 while (true) {
21722156 var statx = std.mem.zeroes(linux.Statx);
2173 switch (sys.errno(sys.statx(
2174 file.handle,
2175 "",
2176 linux.AT.EMPTY_PATH,
2177 .{
2178 .TYPE = true,
2179 .MODE = true,
2180 .ATIME = true,
2181 .MTIME = true,
2182 .CTIME = true,
2183 .INO = true,
2184 .SIZE = true,
2185 .NLINK = true,
2186 },
2187 &statx,
2188 ))) {
2157 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_mask, &statx))) {
21892158 .SUCCESS => {
21902159 current_thread.endSyscall();
21912160 return statFromLinux(&statx);
......@@ -11113,15 +11082,22 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
1111311082 };
1111411083}
1111511084
11085const linux_statx_mask: std.os.linux.STATX = .{
11086 .TYPE = true,
11087 .MODE = true,
11088 .ATIME = true,
11089 .MTIME = true,
11090 .CTIME = true,
11091 .INO = true,
11092 .SIZE = true,
11093 .NLINK = true,
11094};
11095
1111611096fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
11117 if (!stx.mask.TYPE) return error.Unexpected;
11118 if (!stx.mask.MODE) return error.Unexpected;
11119 if (!stx.mask.ATIME) return error.Unexpected;
11120 if (!stx.mask.MTIME) return error.Unexpected;
11121 if (!stx.mask.CTIME) return error.Unexpected;
11122 if (!stx.mask.INO) return error.Unexpected;
11123 if (!stx.mask.SIZE) return error.Unexpected;
11124 if (!stx.mask.NLINK) return error.Unexpected;
11097 const actual_mask_int: u32 = @bitCast(stx.mask);
11098 const wanted_mask_int: u32 = @bitCast(linux_statx_mask);
11099 if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;
11100
1112511101 const atime = stx.atime;
1112611102 const mtime = stx.mtime;
1112711103 const ctime = stx.ctime;