Skip to content

Commit

Permalink
[7.1.0] Optimize out a stat call. (bazelbuild#21388)
Browse files Browse the repository at this point in the history
Calling isDirectory on a Path requires an extra system call. In most
Unix filesystems, readdir is able to return the type directly (see the
implementation in NativePosixFiles).

PiperOrigin-RevId: 607678196
Change-Id: I5d09f11d6aa4702a6f7a0310cca26616cfbac6d1
  • Loading branch information
tjgq authored Feb 16, 2024
1 parent f3359d8 commit 3dc745a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
import com.google.devtools.build.lib.util.io.AsynchronousMessageOutputStream;
import com.google.devtools.build.lib.util.io.MessageOutputStream;
import com.google.devtools.build.lib.vfs.DigestHashFunction;
import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.IORuntimeException;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.lib.vfs.XattrProvider;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
Expand Down Expand Up @@ -101,8 +103,9 @@ private void run() throws IOException, InterruptedException {

private void visitSubdirectory(Path dir) {
try {
for (Path child : dir.getDirectoryEntries()) {
if (child.isDirectory()) {
for (Dirent dirent : dir.readdir(Symlinks.FOLLOW)) {
Path child = dir.getChild(dirent.getName());
if (dirent.getType() == Dirent.Type.DIRECTORY) {
execute(() -> visitSubdirectory(child));
continue;
}
Expand Down

0 comments on commit 3dc745a

Please sign in to comment.