fix(eval): avoid stat calls in builtins.readDir
Use entry.file_type() instead of entry.metadata().file_type() to avoid unnecessary stat syscalls. The file_type() method uses the cached d_type field from the readdir() syscall when available, eliminating the need for additional filesystem access. This matches the behavior described in https://github.com/NixOS/nix/pull/13412 where readDir should only read directory entries without stat'ing each file. Change-Id: I8983f84a7cff28b2c892d5829b9880ed22be4389 Reviewed-on: https://cl.snix.dev/c/snix/+/30596 Reviewed-by: Florian Klink <flokli@flokli.de> Tested-by: besadii
This commit is contained in:
parent
e9073eeddd
commit
ba0a01e7aa
1 changed files with 4 additions and 1 deletions
|
|
@ -152,7 +152,10 @@ impl EvalIO for StdIO {
|
|||
|
||||
for entry in path.read_dir()? {
|
||||
let entry = entry?;
|
||||
let file_type = entry.metadata()?.file_type();
|
||||
// Use entry.file_type() instead of entry.metadata() to avoid stat syscalls.
|
||||
// file_type() uses the d_type field from the readdir() syscall (when available),
|
||||
// which is cached in the DirEntry and doesn't require additional filesystem access.
|
||||
let file_type = entry.file_type()?;
|
||||
|
||||
let val = if file_type.is_dir() {
|
||||
FileType::Directory
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue