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(...@@ -1919,23 +1919,7 @@ fn dirStatFileLinux(
1919 try current_thread.beginSyscall();1919 try current_thread.beginSyscall();
1920 while (true) {1920 while (true) {
1921 var statx = std.mem.zeroes(linux.Statx);1921 var statx = std.mem.zeroes(linux.Statx);
1922 const rc = sys.statx(1922 switch (sys.errno(sys.statx(dir.handle, sub_path_posix, flags, linux_statx_mask, &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)) {
1939 .SUCCESS => {1923 .SUCCESS => {
1940 current_thread.endSyscall();1924 current_thread.endSyscall();
1941 return statFromLinux(&statx);1925 return statFromLinux(&statx);
...@@ -2170,22 +2154,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {...@@ -2170,22 +2154,7 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
2170 try current_thread.beginSyscall();2154 try current_thread.beginSyscall();
2171 while (true) {2155 while (true) {
2172 var statx = std.mem.zeroes(linux.Statx);2156 var statx = std.mem.zeroes(linux.Statx);
2173 switch (sys.errno(sys.statx(2157 switch (sys.errno(sys.statx(file.handle, "", linux.AT.EMPTY_PATH, linux_statx_mask, &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 ))) {
2189 .SUCCESS => {2158 .SUCCESS => {
2190 current_thread.endSyscall();2159 current_thread.endSyscall();
2191 return statFromLinux(&statx);2160 return statFromLinux(&statx);
...@@ -11113,15 +11082,22 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {...@@ -11113,15 +11082,22 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t {
11113 };11082 };
11114}11083}
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
11116fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {11096fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat {
11117 if (!stx.mask.TYPE) return error.Unexpected;11097 const actual_mask_int: u32 = @bitCast(stx.mask);
11118 if (!stx.mask.MODE) return error.Unexpected;11098 const wanted_mask_int: u32 = @bitCast(linux_statx_mask);
11119 if (!stx.mask.ATIME) return error.Unexpected;11099 if ((actual_mask_int | wanted_mask_int) != actual_mask_int) return error.Unexpected;
11120 if (!stx.mask.MTIME) return error.Unexpected;11100
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;
11125 const atime = stx.atime;11101 const atime = stx.atime;
11126 const mtime = stx.mtime;11102 const mtime = stx.mtime;
11127 const ctime = stx.ctime;11103 const ctime = stx.ctime;